标签:ble man div problem col ase href str sel
题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840
题解:
1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 int main(){ 6 int n; 7 cin>>n; 8 bool flag1=false,flag2=false,flag3=false,flag4=false,flag5=false; 9 int *p=new int[n]; 10 for(int i=0;i<n;i++) 11 cin>>p[i]; 12 int A1=0,A2=0,A3=0,A5=0; 13 float A4=0.0; 14 int *tempA5=new int[n],kA4=0,kA5=0,cnt=0; 15 for(int i=0;i<n;i++){ 16 int select=p[i]%5+1; 17 switch(select){ 18 case 1: 19 if(p[i]%2==0){ 20 A1+=p[i]; 21 flag1=true; 22 } 23 break; 24 case 2: 25 if(cnt%2!=0) p[i]=-p[i]; 26 A2+=p[i]; 27 cnt++; 28 flag2=true; 29 break; 30 case 3: 31 A3++; 32 flag3=true; 33 break; 34 case 4: 35 A4+=p[i]; 36 kA4++; 37 flag4=true; 38 break; 39 default: 40 tempA5[kA5++]=p[i]; 41 flag5=true; 42 break; 43 } 44 } 45 A4=(float)A4/kA4;//容易错,用强制类型转换 46 A5=tempA5[0]; 47 for(int i=0;i<kA5;i++){ 48 if(tempA5[i]>A5) A5=tempA5[i]; 49 } 50 if(!flag1) cout<<‘N‘<<" "; 51 else cout<<A1<<" "; 52 if(!flag2) cout<<‘N‘<<" "; 53 else cout<<A2<<" "; 54 if(!flag3) cout<<‘N‘<<" "; 55 else cout<<A3<<" "; 56 if(!flag4) cout<<‘N‘<<" "; 57 else cout<<setiosflags(ios::fixed)<<setprecision(1)<<A4<<" ";//不加setiosflags(ios::fixed)输出格式错误 58 if(!flag5) cout<<‘N‘; 59 else cout<<A5; 60 return 0; 61 }
标签:ble man div problem col ase href str sel
原文地址:https://www.cnblogs.com/Gzu_zb/p/9513363.html