A题 hdu 1235 统计同成绩学生人数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1235

统计同成绩学生人数

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16022    Accepted Submission(s): 9214

Problem Description
读入N名学生的成绩,将获得某一给定分数的学生人数输出。
 
Input
测试输入包含若干测试用例,每个测试用例的格式为
第1行:N
第2行:N名学生的成绩,相邻两数字用一个空格间隔。
第3行:给定分数
当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。
 
Output
对每个测试用例,将获得给定分数的学生人数输出。
 
Sample Input
3
80 60 90
60
2
85 66
0
5
60 75 90 55 75 75
0
 
Sample Output
1
0
2
 
Hint
Hint
Huge input, scanf is recommended.
 
Source
 
题目大意:找到给定分数的人数并输出。
 
详见代码。
 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n,a,ans;
 9     int num[1010];
10     while (~scanf("%d",&n))
11     {
12         ans=0;
13         if (n==0)
14             break;
15         for (int i=0;i<n;i++)
16         {
17             scanf("%d",&num[i]);
18         }
19         scanf("%d",&a);
20         for (int i=0;i<n;i++)
21         {
22             if (num[i]==a)
23                 ans++;
24         }
25         printf ("%d
",ans);
26     }
27     return 0;
28 }
原文地址:https://www.cnblogs.com/qq-star/p/4622903.html