也是普普通通的題目
不過我幹嘛cout跟printf交錯用阿 好花((
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int sw=0,sl=0; vector<int> ss; while(n--){ int s; cin>>s; if(s>0)sw++; else sl++; s=abs(s); ss.push_back(s); } sort(ss.begin(),ss.end()); double avg=0.0; for(int i=1;i<(int)ss.size()-1;i++){ avg+=(double)ss[i]; } cout<<"Average time: "; printf("%.3f",avg/(double)(ss.size()-2)); cout<<" sec(s).\n"; cout<<"Winning rate: "; printf("%.3f",100.0*(double)sw/(double)(sw+sl)); cout<<" %.\n"; } |
沒有留言:
張貼留言