Y:年齡與疾病

總時間限制: 
1000ms
 
內存限制: 
65536kB
描述

某醫院想統計一下某項疾病的得到與否與年齡是否有關,須要對之前的診斷記錄進行整理,按照0-1八、19-3五、36-60、61以上(含61)四個年齡段統計的患病人數佔總患病人數的比例。ios

輸入
共2行,第一行爲過往病人的數目n(0 < n <= 100),第二行爲每一個病人患病時的年齡。
輸出
按照0-1八、19-3五、36-60、61以上(含61)四個年齡段輸出該段患病人數佔總患病人數的比例,以百分比的形式輸出,精確到小數點後兩位。每一個年齡段佔一行,共四行。
樣例輸入
10
1 11 21 31 41 51 61 71 81 91
樣例輸出
20.00%
20.00%
20.00%
40.00%
 1 #include <iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,a[101],a18=0,a35=0,a60=0,a61=0;
 7     cin >> n;
 8     for (int i=0;i<n;++i)
 9     {
10         cin >> a[i];
11         if (a[i]>=0&&a[i]<=18)
12         {
13             a18++;
14         }
15         if (a[i] >= 19 && a[i] <= 35)
16         {
17             a35++;
18         }
19         if (a[i] >= 36 && a[i] <= 60)
20         {
21             a60++;
22         }
23         if (a[i] >= 61)
24         {
25             a61++;
26         }
27     }
28     printf("%.2f%%\n", a18*100.0 / n);
29     printf("%.2f%%\n", a35*100.0 / n);
30     printf("%.2f%%\n", a60*100.0 / n);
31     printf("%.2f%%\n", a61*100.0 / n);
32     return 0;
33 }
相關文章
相關標籤/搜索