hash的应用例2.5统计同成绩学生人数

题目描述

读入N名学生的成绩,将获得某一给定分数的学生人数输出。

输入描述:

测试输入包含若干测试用例,每个测试用例的格式为


第1行:N
第2行:N名学生的成绩,相邻两数字用一个空格间隔。
第3行:给定分数

当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。

输出描述:

对每个测试用例,将获得给定分数的学生人数输出。
示例1

输入

3
80 60 90
60
2
85 66
0
5
60 75 90 55 75
75
0

输出

1
0
2

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     while(cin>>n&&n)
 7     {
 8         int ans[101]={0};
 9         for(int i=0;i<n;i++)
10         {
11             int s;
12             cin>>s;
13             ans[s]++;
14         }
15         int x;
16         cin>>x;
17         cout<<ans[x]<<endl;
18     }
19 
20     return 0;
21 }
View Code

猜你喜欢

转载自www.cnblogs.com/qing123tian/p/11166070.html