Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
121784 胡海峰老师 18患病人数占总患病人数的比例 C++ Accepted 1 MS 272 KB 750 2025-06-08 11:21:33

Tests(10/10):


Code:

#include <iostream> #include <iomanip> using namespace std; int main() { int n; cin >> n; int age; int count[4] = {0}; // 分别统计0-18,19-35,36-60,61+四个年龄段 for (int i = 0; i < n; ++i) { cin >> age; if (age <= 18) { count[0]++; } else if (age <= 35) { count[1]++; } else if (age <= 60) { count[2]++; } else { count[3]++; } } // 计算并输出百分比 cout << fixed << setprecision(2); for (int i = 0; i < 4; ++i) { double percentage = (static_cast<double>(count[i]) / n) * 100; cout << percentage << "%" << endl; } return 0; }