PTA乙级1012
作者:互联网
注意点 第二个交错求和要用个数来记录是否有数字满足 而不是判断是否为0 否则有一个点不过
AC代码
#include<iostream>
using namespace std;
int a1,a2,a3,a4,a5;
int fl=1;
int maxx=-1;
int i,j,k;
int main()
{
int n;
cin>>n;
int x;
while(n--)
{
cin>>x;
if(x%5==0)
{
if(x%2==0)
a1+=x;//he
}
else if(x%5==1)
{
a2+=x*fl;
fl*=-1;//jiaocuo
k++;
}
else if(x%5==2)
{
i++;//geshu
}
else if(x%5==3)
{
a4+=x;//pingjunshu
j++;
}
else if(x%5==4)
{
if(x>maxx)
maxx=x;//zuidazhi
}
}
if(a1==0)
printf("N ");
else
printf("%d ",a1);
if(k==0)
printf("N ");
else
printf("%d ",a2);
if(i==0)
printf("N ");
else
printf("%d ",i);
if(j==0)
printf("N ");
else
printf("%.1lf ",(double)a4/j);
if(maxx==-1)
printf("N\n");
else
printf("%d\n",maxx);
}
标签:maxx,int,PTA,else,a1,乙级,printf,x%,1012 来源: https://blog.csdn.net/m0_51305283/article/details/116947536