周一(PTA简单题)例
#include<iostream> #include<iomanip> using namespace std; int main() { int N,i,sex,b=0,g=0;float score,aver1,aver2,aver3,b1=0.0,g1=0.0; cin>>N; for(i=0;i<N;i++) {cin>>sex;cin>>score; if(sex==1){b+=1;b1+=score;} else{g+=1;g1+=score;} } aver1=(b1+g1)/N; if(b!=0&&g!=0) { aver2=b1/b; aver3=g1/g; cout<<setiosflags(ios::fixed)<<setprecision(1)<<aver1<<" "<<setiosflags(ios::fixed)<<setprecision(1)<<aver2<<" "<<setiosflags(ios::fixed)<<setprecision(1)<<aver3; } if(b==0&&g!=0) { aver3=g1/g; cout<<setiosflags(ios::fixed)<<setprecision(1)<<aver1<<" "<<"X"<<" "<<setiosflags(ios::fixed)<<setprecision(1)<<aver3; } if(b!=0&&g==0) { aver2=b1/b; cout<<setiosflags(ios::fixed)<<setprecision(1)<<aver1<<" "<<setiosflags(ios::fixed)<<setprecision(1)<<aver2<<" "<<"X";} return 0; }