#include<stdio.h>
int a[1010];
int main()
{
int n;
int a1,a2,a3,a5;
double a4,sum;
int flag=1;
int count=0;
a1=a2=a3=a4=a5=sum=0;
scanf("%d",&n);
int i,j;
int b1,b2,b3,b4,b5;
b1=b2=b3=b4=b5=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]%5==0&&a[i]%2==0)
{
a1+=a[i];
b1=1;
}
else if(a[i]%5==1)
{
a2+=flag*a[i];
flag=-flag;
b2=1;
}
else if(a[i]%5==2)
{
a3++;
b3=1;
}
else if(a[i]%5==3)
{
sum+=a[i];
count++;
b4=1;
}
else if(a[i]%5==4)
{
if(a[i]>a5)
a5=a[i];
b5=1;
}
}
a4=sum/count;
if(b1==1)
printf("%d ",a1);
else
printf("N ");
if(b2==1)
printf("%d ",a2);
else
printf("N ");
if(b3==1)
printf("%d ",a3);
else
printf("N ");
if(b4==1)
printf("%.1lf ",a4);
else
printf("N ");
if(b5==1)
printf("%d\n",a5);
else
printf("N\n");
return 0;
}
此题提醒我要注意审题,题目中输出有多种情况
PAT——乙级1012(数字分类,交错求和)
最新推荐文章于 2024-05-02 15:49:12 发布