题目10:统计同成绩学生人数

来源:互联网 发布:wait await java 编辑:程序博客网 时间:2024/06/18 17:51

http://ac.jobdu.com/problem.php?cid=1040&pid=9

题目描述:
读入N名学生的成绩,将获得某一给定分数的学生人数输出。
输入:
测试输入包含若干测试用例,每个测试用例的格式为


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

当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。
输出:
对每个测试用例,将获得给定分数的学生人数输出。
样例输入:
380 60 9060285 660560 75 90 55 75750
样例输出:
102
// 题目10:统计同成绩学生人数.cpp: 主项目文件。#include "stdafx.h"#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <string>#include <set>#include <map>#include <queue>#include <stack>using namespace std;const int N=103;int hashTable[N];int main(){    //freopen("F:\\test.txt","r",stdin);    //freopen("F:\\output.txt","w",stdout);int n;while(cin>>n){if(n==0)break;memset(hashTable,0,sizeof(hashTable));for(int i=0;i<n;i++){int tmp;cin>>tmp;hashTable[tmp]++;}int needNum;cin>>needNum;cout<<hashTable[needNum]<<endl;}    return 0;}


原创粉丝点击