PAT乙级 1012 数字分类
作者:
YAX_AC
,
2024-08-05 12:35:42
,
所有人可见
,
阅读 21
PAT乙级 1012 数字分类
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int main()
{
int a1=0,a2=0,cnt2=0,a3=0,sum4=0,cnt4=0,a5=0;
double a4=0.0;
int b=1;
//易错点,如果将a1,a2,a3等等是否为0作为判断N,将会造成错误的情况,如果算出a1,a2等等本身是0会造成歧义
//所以另开count1,count2等等作为判断条件
int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0;
cin>>n;
for(int i = 0; i<n; i++)
{
int x; cin>>x;
if(x%5==0 && x%2==0)
{
count1++;a1+=x;
}
if(x%5==1)
{
count2++;
a2+=b*x;
b=-b;
}
if(x%5==2)
{
count3++;a3++;
}
if(x%5==3)
{
count4++;
cnt4++;
sum4+=x;
}
if(x%5==4)
{
count5++;
a5=a5>x?a5:x;
}
}
if(count1)cout<<a1<<" ";
else cout<<"N ";
if(count2)cout<<a2<<" ";
else cout<<"N ";
if(count3)cout<<a3<<" ";
else cout<<"N ";
if(count4) printf("%.1lf ",(double)sum4/cnt4);
else cout<<"N ";
if(count5)cout<<a5;
else cout<<"N";
return 0;
}