题目:https://pintia.cn/problem-sets/994805260223102976/exam/problems/994805311146147840
经过千辛万苦终于拿满了,但是代码行数太多了233,望各位能给个优化的意见。
#include <stdio.h>
int main()
{
int N,i,A[6]={0},flag=1,count=0,temp=0;
scanf("%d",&N);
int num[N];
for(i=0;i<N;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<N;i++)
{
switch(num[i] % 5)
{
case 0:
{
if(num[i] % 2 == 0)
A[1] += num[i];
break;
}
case 1:
{
A[2] += flag*num[i];
flag=-flag;
temp=1;
break;
}
case 2:
{
A[3]++;
break;
}
case 3:
{
A[4] += num[i];
count++;
break;
}
case 4:
{
if(num[i]>A[5])
A[5]=num[i];
break;
}
}
}
for(i=1;i<6;i++)
{
if(i != 1)
printf(" ");
switch(i)
{
case 1:
case 3:
case 4:
case 5:
{
if(A[i] != 0)
{
if(i==4)
{
printf("%.1f",(double)A[4]/count);
break;
}
printf("%d",A[i]);
}
else
printf("N");
break;
}
case 2:
{
if(temp == 1)
printf("%d",A[2]);
else
printf("N");
break;
}
}
}
return 0;
}