# 1012. 数字分类 (20)-PAT乙级

### 题目：

A1 = 能被5整除的数字中所有偶数的和；
A2 = 将被5除后余1的数字按给出顺序进行交错求和，即计算n1-n2+n3-n4…；
A3 = 被5除后余2的数字的个数；
A4 = 被5除后余3的数字的平均数，精确到小数点后1位；
A5 = 被5除后余4的数字中最大数字。

13 1 2 3 4 5 6 7 8 9 10 20 16 18

30 11 2 9.7 9

8 1 2 4 5 6 7 9 16

N 11 2 N 9

### 解答：

#include<iostream>
using namespace std;

int main()
{
int n;
cin >> n;
int *num = new int[n];
int a = 0, b = 0, f = 1;
int con2=0;
float con3 = 0.0, sum3 = 0.0;
int ma4 = num[0];
int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0, flag5 = 0;
for (int i = 0; i < n; i++)
{
cin >> num[i];
if (num[i] % 10 == 0)
{
a += num[i];
flag1 = 1;
}
else if (num[i] %5== 1)
{
b = b + f*num[i];
f *= -1;
flag2 = 1;
}
else if (num[i] % 5 == 2)
{
con2++;
flag3 = 1;
}
else if (num[i] % 5 == 3)
{
sum3 += num[i];
con3=con3+1.0;
flag4 = 1;
}
else if (num[i] % 5 == 4)
{
if (ma4 <= num[i])
ma4 = num[i];
flag5 = 1;
}
}
sum3 /= con3;
if (flag1 == 0)
cout << "N ";
else
cout << a << " ";
if (flag2 == 0)
cout << "N ";
else
cout << b << " ";
if (flag3 == 0)
cout << "N ";
else
cout << con2 << " ";
if (flag4 == 0)
cout << "N ";
else
printf("%.1f ", sum3);//第一次提交有三个测试点格式错误//不是这里
if (flag5 == 0)
cout << "N";
//答案输出格式错误就应该检查输出流部分而我一直没找对地方、、
//检查了一遍代码运算，原来是“N ”改成“N”就对了
else
cout << ma4;
delete[] num;
return 0;
}//隔了半天没找到错误在哪里，最后找到了，如上
//细心+逻辑辨别（长心）