PAT (Basic Level) Practice (中文) 1012 数字分类
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 using namespace std; 3 int num[5],sumn[5],n; 4 void init(); 5 void read(); 6 void deal(); 7 int main(){ 8 init(); 9 read(); 10 deal(); 11 return 0; 12 } 13 void init(){ 14 for(int i=0;i<=4;i++){ 15 num[i] = 0; 16 sumn[i] = 0; 17 } 18 return ; 19 } 20 void read(){ 21 int data,flag=-1; 22 scanf("%d",&n); 23 for(int i=1;i<=n;i++){ 24 scanf("%d",&data); 25 switch(data%5){ 26 case 0: //偶数和 27 if(data%2==0) {num[0]++;sumn[0]+=data;} 28 break; 29 case 1: //出顺序进行交错求和 30 num[1]++; 31 sumn[1]+=((-1)*flag*data); 32 flag = -flag; 33 break; 34 case 2: //数字的个数 35 num[2]++;break; 36 case 3: //数字的平均数 37 num[3]++; 38 sumn[3]+=data; 39 break; 40 case 4: //数字中最大数字 41 num[4]++; 42 if((num[4]>1&&sumn[4]<data)||(num[4]==1)) sumn[4] = data; 43 break; 44 } 45 } 46 } 47 void deal(){ 48 if(num[0]==0) printf("N "); 49 else printf("%d ",sumn[0]); 50 51 if(num[1]==0) printf("N "); 52 else printf("%d ",sumn[1]); 53 54 if(num[2]==0) printf("N "); 55 else printf("%d ",num[2]); 56 57 if(num[3]==0) printf("N "); 58 else printf("%.1f ",((float)(sumn[3])/num[3])); 59 60 if(num[4]==0) printf("N"); 61 else printf("%d",sumn[4]); 62 63 }