3: Age and Disease
- Total time limit:
- 1000ms
- Memory limit:
- 65536kB
- describe
-
A hospital wants to count whether the acquisition of a certain disease is related to age. It needs to sort out the previous diagnosis records and count according to the four age groups of 0-18, 19-35, 36-60, 61 and above (including 61). the proportion of patients with the disease to the total number of patients.
- enter
- There are 2 lines in total, the first line is the number n of past patients (0 < n <= 100), and the second line is the age of each patient at the time of illness.
- output
- According to the four age groups of 0-18, 19-35, 36-60, 61 and above (including 61), output the proportion of the number of patients in this period to the total number of patients, output in the form of a percentage, accurate to two decimal places. One row for each age group, four rows in total.
- sample input
-
10 1 11 21 31 41 51 61 71 81 91
- Sample output
-
20.00% 20.00% 20.00% 40.00%
#include<iostream> #include<iomanip> using namespace std; int main(){ const int MAX=200; int one=0,two=0,thr=0,four=0; double x,y,o,p; int a[MAX]; int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]>=0&&a[i]<=18) one++; else if(a[i]>=19&&a[i]<=35) two++; else if(a[i]>=36&&a[i]<=60) thr++; else if(a[i]>=61) four++; } x = (double)one/n*100; y = (double)two/n*100; o = (double)thr/n*100; p = (double)four/n*100; cout<<setiosflags(ios::fixed)<<setprecision(2)<<x<<"%"<<endl; cout<<setiosflags(ios::fixed)<<setprecision(2)<<y<<"%"<<endl; cout<<setiosflags(ios::fixed)<<setprecision(2)<<o<<"%"<<endl; cout<<setiosflags(ios::fixed)<<setprecision(2)<<p<<"%"<<endl; return 0; }