文章

84

粉丝

2

获赞

601

访问

28.6k

头像
统计同成绩学生人数 题解:
P1329 浙江大学机试题
发布于2026年2月9日 11:46
阅读数 105

#include<iostream>
#include<unordered_map>

using namespace std;

int main() {
	int n;
	while (cin >> n && n != 0) {
		unordered_map<int, int> mp;
		while (n -- ) {
			int x;
			cin >> x;
			mp[x] ++ ;
		}
		int score;
		cin >> score;
		auto it = mp.find(score);
		if (it != mp.end()) {
			cout << mp[score] << endl;
		} else {
		    cout << '0' << endl;
		}
	}
	return 0;
}
#include<iostream>
#include<vector>

using namespace std;

int main() {
	
	int n;
	while (cin >> n && n != 0) {
		vector<int> v;
		for (int i = 0; i < n; i ++ ) {
			int x;
			cin >> x;
			v.push_back(x);
		}
		int score;
		cin >> score;
		int cnt = 0;
		for (auto c : v) {
			if (c == score)
				cnt ++ ;
		}
		cout << cnt << endl;
	}
	
	return 0;	
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发