李雨昊 • 6个月前
#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;
}
评论: