1012 数字分类 (20 分)
#include <iostream> #include <string> #include <iomanip> using namespace std; int main(){ double sum4 = 0.0; int n, t, k = -1, cnt = 0, cnt2 = 0, max = 0, sum1 = 0, sum2 = 0, sum3 = 0; cin >> n; while (n--){ cin >> t; if (t % 10 == 0) sum1 += t; else if (t % 5 == 1){ k = -k; sum2 += t * k; cnt2++; // 这个地方需要注意,若果没有这个计数器的话答案总是WA, 不知道为啥 } else if (t % 5 == 2) sum3++; else if (t % 5 == 3){ sum4 += t; cnt++; } else if (t % 5 == 4){ if (max < t) max = t; } } if (cnt > 0) sum4 /= cnt; if (sum1 == 0) cout << "N" << ' '; else cout << sum1 << ' '; if (cnt2 == 0) cout << "N" << ' '; else cout << sum2 << ' '; if (sum3 == 0) cout << "N" << ' '; else cout << sum3 << ' '; if (sum4 == 0.0) cout << "N" << ' '; else cout << fixed << setprecision(1) << sum4 << ' '; if (max == 0) cout << "N" << endl; else cout << max << endl; return 0; }