cjweffort

博客园 首页 联系 订阅 管理

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

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


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

当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。
输出:
对每个测试用例,将获得给定分数的学生人数输出。
样例输入:
3
80 60 90
60
2
85 66
0
5
60 75 90 55 75
75
0
样例输出:
1
0
2
// 题目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;
}


posted on 2013-03-02 11:31  cjweffort  阅读(216)  评论(0编辑  收藏  举报