年龄和疾病

3:年龄与疾病


总时间限制: 
1000ms
内存限制: 
65536kB
描述

某医院想统计一下某项疾病的获得与否与年龄是否有关,需要对以前的诊断记录进行整理,按照0-18、19-35、36-60、61以上(含61)四个年龄段统计的患病人数占总患病人数的比例。

输入
共2行,第一行为过往病人的数目n(0 < n <= 100),第二行为每个病人患病时的年龄。
输出
按照0-18、19-35、36-60、61以上(含61)四个年龄段输出该段患病人数占总患病人数的比例,以百分比的形式输出,精确到小数点后两位。每个年龄段占一行,共四行。
样例输入
10
1 11 21 31 41 51 61 71 81 91
样例输出
20.00%
20.00%
20.00%
40.00%










扫描二维码关注公众号,回复: 308691 查看本文章








 
 
#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;
}

猜你喜欢

转载自blog.csdn.net/i_hope_soar/article/details/79332437