题目链接: 酷町堂:5004
5004 统计人数2
经验值:800 时间限制:1000毫秒 内存限制:128MB
题目描述 De**ion
班里现在有n(n<=100)位学生。某次考试结束后,知道了每位学生的总分(整数),现在还要再统计一些数据:
某个分数段考的人数各是多少人。
输入描述 Input De**ion
输入数据共 2 行。第一行是 3个整数n,a,b,n表示总共有n名同学,a,b表示要统计的分数段,数据保证a<=b,接下来 1 行,共有 n 个由空格分隔的正整数,表示每一位学生的总分
输出描述 Output De**ion
共 1 行
表示对应分数考的人数,要求统计a~b这个分数段(包括a和b)
样例输入 Sample Input
5 80 90 85 92 88 92 95
样例输出 Sample Output
0 0 0 0 0 1 0 0 1 0 0
数据范围及提示 Data Size & Hint
分数在0~100之间
0分
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
int n,j=1,cnt;
int b,c;
int a[10000];
int main(){
cin>>n>>b>>c;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=b;i<c;i++){
if(i==a[j]){
j++;
cnt++;
i--;
}else if(cnt>=0){
cout<<cnt<<" ";
cnt=0;
}else{
cout<<0<<" ";
}
}
return 0;
}