统计同成绩学生人数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21248 Accepted Submission(s): 11987
Problem Description
读入N名学生的成绩,将获得某一给定分数的学生人数输出。
Input
测试输入包含若干测试用例,每个测试用例的格式为
第1行:N
第2行:N名学生的成绩,相邻两数字用一个空格间隔。
第3行:给定分数
当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。
Output
第1行:N
第2行:N名学生的成绩,相邻两数字用一个空格间隔。
第3行:给定分数
当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。
对每个测试用例,将获得给定分数的学生人数输出。
Sample Input
3 80 60 90 60 2 85 66 0 5 60 75 90 55 75 75 0
1 0 2Huge input, scanf is recommended.HintHint
问题链接:HDU1235 统计同成绩学生人数
问题简述:参见上文。
问题分析:(略)
程序说明:这是一个大水题,给定的分数在后面输入,所以需要数组。题记:(略)
AC的C语言程序如下:
/* HDU1235 统计同成绩学生人数 */
#include <stdio.h>
#define N 1000
int score[N];
int main(void)
{
int n, grade, cnt, i;
while(scanf("%d", &n) && n) {
for(i=0; i<n; i++)
scanf("%d", &score[i]);
scanf("%d", &grade);
cnt = 0;
for(i=0; i<n; i++)
if(score[i] == grade)
cnt++;
printf("%d\n", cnt);
}
return 0;
}
AC的C++语言程序如下:
/* HDU1235 统计同成绩学生人数 */
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 1000;
int score[N];
int main()
{
int n, grade, cnt;
while(scanf("%d", &n) && n) {
for(int i=0; i<n; i++)
scanf("%d", &score[i]);
scanf("%d", &grade);
cnt = 0;
for(int i=0; i<n; i++)
if(score[i] == grade)
cnt++;
printf("%d\n", cnt);
}
return 0;
}