#include <iostream> #include <iomanip> using namespace std; int main() { int n, num; int a[6] = { 0 }; int b = 1; int ct1 = 0, ct2 = 0; cin >> n; while (n--){ cin >> num; if (num % 10 == 0) a[1] += num; if (num % 5 == 1) { ++ct1; a[2] += b*num; b = -b; } if (num % 5 == 2) ++a[3]; if (num % 5 == 3){ ++ct2; a[4] += num; } if (num % 5 == 4){ if (num > a[5]) a[5] = num; } } double a4 = 1.0 * a[4] / ct2; for (int i = 1; i < 6; ++i){ if (i>1) cout << " "; if (a[i] == 0) { if (i == 2 && ct1 > 0) { //用a[i]==0判断时,a[2]里面可能经过多次正负相加得到0,从而误输出“N” cout << "0"; continue; } cout << "N"; continue; } if (i == 4) { cout << fixed << setprecision(1) << a4; continue; } cout << a[i]; } return 0; }
PAT(B)1012. 数字分类 (20)
最新推荐文章于 2024-06-18 16:38:54 发布