Foreword:
21 Postgraduate entrance examination, I am gnawing "Algorithm Notes", whether I can enter the retest or not to record the garbage code written on the road.
answer:
#include<cstdio>
int main()
{
int n,a[5]={
0},num,tag=0,taga2=0;
double mod3=0,count3=0;
scanf("%d",&n);
while(n--){
scanf("%d",&num);
if(num%5==0&&num%2==0) //测试点5、6,注意余0的奇数
a[0]+=num;
else if(num%5==1){
if(tag==0){
a[1]+=num;
tag=1;
taga2 = 1; //测试点8,注意未操作导致a[2]==0和计算结果为0不同
}
else{
a[1]-=num;
tag=0;
}
} else if(num%5==2)
a[2]++;
else if(num%5==3){
count3++;
a[3]+=num;
}
else if(num%5==4){
if(a[4]<num)
a[4]=num;
}
}
mod3=a[3]/count3;
if (a[0] == 0)
printf("N ");
else
printf("%d ", a[0]);
if (a[1] == 0 && taga2 == 1)
printf("0 ");
else if (a[1] == 0)
printf("N ");
else
printf("%d ", a[1]);
if (a[2] == 0)
printf("N ");
else
printf("%d ", a[2]);
if (a[3] == 0)
printf("N ");
else
printf("%.1lf ", mod3);
if (a[4] == 0)
printf("N");
else
printf("%d", a[4]);
return 0;
}
This question is really boring. Test points 5, 6, and 8 are really hard to think of. I feel that there are too many redundancies to repair.