1153 Decode Registration Card of PAT 最后两个测试点

不使用printf最后两个测试点会过不去,将COUT换成printf后就可以通过了。

#include<bits/stdc++.h>	
#include<unordered_map>
using namespace std;
struct stu {
	string NO;
	int score;
	stu(string a,int b):NO(a),score(b){}
};
struct exam_room {
	string NO;
	int stu_num;
	exam_room(string a, int b) :NO(a), stu_num(b) {}
};
unordered_map<char,vector<stu> > mp1;
unordered_map<string, int>mp_num, mp_score;//记录考场人数,考场总分数
unordered_map<string, unordered_map<string , int> > mp3;
int cnt = 1;
int cmp(stu a, stu b) {
	if (a.score != b.score) return a.score > b.score;
	else return a.NO < b.NO;
}
int cmp1(exam_room a, exam_room b) {
	if (a.stu_num != b.stu_num) return a.stu_num > b.stu_num;
	else return a.NO < b.NO;
}
void case_1(char c) {
	printf("Case %d: 1 %c\n", cnt++, c);
	if (mp1[c].size() == 0) {
		printf("NA\n");
		return;
	}
	sort(mp1[c].begin(), mp1[c].end(), cmp);
	for (auto it = mp1[c].begin(); it != mp1[c].end(); it++) {
		printf("%s %d\n", it->NO.c_str(), it->score);
	}
}

void case_2(string str) {
	printf("Case %d: 2 %s\n", cnt++, str.c_str());
	if (mp_num[str] == 0) {
		printf("NA\n");
		return;
	}
	printf("%d %d\n", mp_num[str], mp_score[str]);
}

void case_3(string str) {
	printf("Case %d: 3 %s\n", cnt++, str.c_str());
	if (mp3[str].size() == 0) {
		printf("NA\n");
		return;
	}
	vector<exam_room> ans;
	for (auto it = mp3[str].begin(); it != mp3[str].end(); it++) {
		ans.push_back(exam_room(it->first, it->second));
	}
	sort(ans.begin(), ans.end(), cmp1);
	for (auto it = ans.begin(); it != ans.end(); it++) {
		printf("%s %d\n", it->NO.c_str(), it->stu_num);
	}
}
int main() {
#ifdef ONLINE_JUDGE
#else
	freopen("Text.txt", "r", stdin);
#endif // ONLINE_JUDGE

	int N, M; scanf("%d %d", &N, &M);
	string no; int score;
	for (int i = 0; i < N; i++) {
		cin >> no >> score;
		string examroom_no, exam_data;
		examroom_no = no.substr(1, 3);
		exam_data = no.substr(4, 6);
		mp1[no[0]].push_back(stu(no, score));//该等级考试人数++
		mp_num[examroom_no]++;//该考场人数++
		mp_score[examroom_no] += score;//该考场的总分加入该考生的分数、
		mp3[exam_data][examroom_no]++;//考试日期为exam_data考场号为exam_room的人数++
	}
	for (int i = 0; i < M; i++) {
		int t; string p;
		cin >> t >> p;
		switch (t)
		{
			case 1: case_1(p[0]); break;
			case 2: case_2(p); break;
			case 3: case_3(p); break;
			default: break;
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_39072627/article/details/108330791