牛客网PAT练习场-数字分类

签到题 地址:https://www.nowcoder.com/pat/6/problem/4078

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main(){
 5     int A[6]={0};//存分类数据
 6     int a[6]={0};//标记是否有数据个数
 7     int t;
 8     int flag=0;//A3的标记变量
 9     int num=0;//A4的统计变量
10     scanf("%d",&t);
11     //IF处理操作
12     for(int i=0;i<t;i++){
13         int temp;
14         scanf("%d",&temp);
15         if((temp%5==0)&&(temp%2==0)){
16             a[1]=1;
17             A[1]+=temp;
18         }
19         if(temp%5==1){
20             a[2]=1;
21             if(flag==0){
22                 A[2]+=temp;
23                 flag=1;
24             }else{
25                 A[2]-=temp;
26                 flag=0;
27             }
28         }
29         if(temp%5==2){
30             a[3]=1;
31             A[3]++;}
32         if(temp%5==3){
33             a[4]=1;
34             A[4]+=temp;
35             num++;
36         }
37         if(temp%5==4){
38             a[5]=1;
39             A[5]=A[5]>temp?A[5]:temp;
40         }
41     }
42      //格式输出   
43     for(int i=1;i<6;i++){
44         if(a[i]){
45             if(i==4){
46                 printf("%.1lf",A[i]*1.0/num);
47             }else{
48                 printf("%d",A[i]);
49             }
50 
51         }else{
52             printf("N");
53         }
54         if(i!=5)printf(" ");
55     }
56     return 0;
57 }

猜你喜欢

转载自www.cnblogs.com/cutelife/p/11741351.html