#include<iostream>
#include<string>
#include <iomanip>
#include<sstream>
using namespace std;
int main()
{
int noUse = 0;
cin >> noUse;
string s;
getline(cin, s);
int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0;
int t, num1 = 0, num2 = 0, tag2 = 0, num3 = 0, max5 = 0;
double sum4 = 0.0, num4 = 0.0, aver4 = 0.0;
for (istringstream sin(s); sin >> t;) {
if (t % 5 == 0 && t % 2 == 0) {
num1 += t;
a1++;
}
if (t % 5 == 1) {
if (tag2 == 0) {
num2 += t;
tag2 = 1;
continue; //跳过下面这个if
}
if (tag2 == 1) {
num2 -= t;
tag2 = 0;
}
a2++;
}
if (t % 5 == 2) {
num3++;
a3++;
}
if (t % 5 == 3) {
num4++;
sum4 += t;
a4++;
}
if (t % 5 == 4) {
if (t > max5) {
max5 = t;
}
a5++;
}
}
aver4 = sum4 / num4;
if (a1 == 0) {
cout << "N" << " ";
}
else {
cout << num1 << " ";
}
if (a2 == 0) {
cout << "N" << " ";
}
else {
cout << num2 << " ";
}
if (a3 == 0) {
cout << "N" << " ";
}
else {
cout << num3 << " ";
}
if (a4 == 0) {
cout << "N" << " ";
}
else {
cout << fixed << setprecision(1) << aver4 << " ";
}
if (a5 == 0) {
cout << "N";
}
else {
cout << max5;
}
return 0;
}
1012--乙级
最新推荐文章于 2022-10-16 20:04:14 发布
该C++程序读取一串数字,统计其中能被5和2同时整除的数的总和及数量,正负交替的数的差值及出现次数,偶数位置的数的个数,平均值以及最大值。程序通过输入控制台进行数据交互,并以特定格式输出结果。
316

被折叠的 条评论
为什么被折叠?



