题目:
输入格式:
每个输入包含 1 个测试用例。每个测试用例先给出一个不超过 1000 的正整数 N,随后给出 N 个不超过 1000 的待分类的正整数。数字间以空格分隔。
输出格式:
对给定的 N 个正整数,按题目要求计算 A 1~A 5 并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。
若其中某一类数字不存在,则在相应位置输出 N。
输入样例 1:
13 1 2 3 4 5 6 7 8 9 10 20 16 18
输出样例 1:
30 11 2 9.7 9
输入样例 2:
8 1 2 4 5 6 7 9 16
输出样例 2:
N 11 2 N 9
源码:
//Liu
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
int a[maxn];
int main()
{
int n;
cin >> n;
ll s1=0, s2=0, s0=0;
double s3=0;
int max4=0;
int c1=0, c2=0, c3=0, c4=0, c0=0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
if (!(a[i] % 5) && !(a[i] % 2))
{
s0 += a[i];
c0++;
}
if (a[i] % 5 == 1)
{
if (c1 % 2)
s1 -= a[i];
else s1 += a[i];
c1++;
}
if (a[i] % 5 == 2)
{
c2++;
}
if (a[i] % 5 == 3)
{
s3 += a[i];
c3++;
}
if (a[i] % 5 == 4)
{
max4 = max(max4, a[i]);
c4++;
}
}
if (c0) cout << s0 << " ";
else cout << "N ";
if (c1) cout << s1 << " ";
else cout << "N ";
if (c2) cout << c2 << " ";
else cout << "N ";
if (c3) printf("%.1lf ", s3 / c3);
else cout << "N ";
if (c4) cout << max4;
else cout << "N";
cout << endl;
return 0;
}
原题地址:《PTA1012 数字分类》