Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
93668 卢语涵 18患病人数占总患病人数的比例 C++ Accepted 1 MS 284 KB 1127 2024-10-18 21:11:38

Tests(10/10):


Code:

/**#include<iostream> using namespace std; int main(){ int i,a[31],num=0,k=0; for(int i=1;i<=30;i++){ a[i]=0; } i=1; while(num<15){ if(i>30) i=1; if(a[i]==0) k++; if(k==9){ a[i]=1; k=0; num++; } i++; } for(i=1;i<=30;i++){ if(a[i]==0)cout<<i<<" "; } return 0; }**/ #include<bits/stdc++.h> using namespace std; int main() { int n; double b = 0, c = 0, d = 0, e = 0, a[1000]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (a[i] <= 18) { b++; } else if (a[i] >= 19 && a[i] <= 35) { c++; } else if (a[i] >= 36 && a[i] <= 60) { d++; } else { e++; } } cout << fixed << setprecision(2) << b / n * 100.0 << '%' << endl; cout << fixed << setprecision(2) << c / n * 100.0 << '%' << endl; cout << fixed << setprecision(2) << d / n * 100.0 << '%' << endl; cout << fixed << setprecision(2) << e / n * 100.0 << '%' << endl; return 0; }