其他分享
首页 > 其他分享> > 1095 解码PAT准考证 (25 point(s))

1095 解码PAT准考证 (25 point(s))

作者:互联网

#include <bits/stdc++.h>
using namespace std;

struct Stu{
	string id;
	int score;
	
	bool operator < (Stu s) const{
		if(score != s.score) return score > s.score;
		return id < s.id;
	}
};

struct Room{
	string id;
	int score = 0, peo = 0;
	
	bool operator < (Room r) const{
		if(peo != r.peo) return peo > r.peo;
		return id < r.id;
	}
};

struct Date{
	string id;
	int peo = 0;
	
	bool operator < (Room r) const{
		if(peo != r.peo) return peo > r.peo;
		return id < r.id;
	}
};

int main() {
	int N, M;
	map<char, set<Stu>> stu;
	map<string, Room> room;
	map<string, map<string, Room>> date;
	cin >> N >> M;
	
	while(N--){
		string id;
		int score;
		cin >> id;
		scanf("%d", &score);
		string roomID =  id.substr(1, 3), datetmp =  id.substr(4, 6);

		// 类型1 
		stu[id[0]].insert({id, score});	
		
		// 类型2
		room[roomID].id = roomID;
		room[roomID].score += score;
		room[roomID].peo++;
		
		// 类型3 
		date[datetmp][roomID].id = roomID;
		date[datetmp][roomID].peo++;
	}
	
	for(int i = 1; i <= M; i++){
		int type; string obj; 
		cin >> type >> obj;
		printf("Case %d: %d %s\n", i, type, obj.c_str());
		
		if(type == 1){
			if(stu.find(obj[0]) == stu.end())cout << "NA" << endl;
			else 
				for(auto s: stu[obj[0]])
					printf("%s %d\n", s.id.c_str(), s.score);
		}
		else if(type == 2){
			if(room.find(obj) == room.end())cout << "NA" << endl;
			else printf("%d %d\n", room[obj].peo, room[obj].score);
		}
		else{
			if(date.find(obj) == date.end())cout << "NA" << endl;
			else{
				// 放入 set 集合排序 
				set<Room> out;
				for(auto d: date[obj]) out.insert(d.second);
				for(auto o: out)
					printf("%s %d\n", o.id.c_str(), o.peo);
			} 
			
		}
	}
}
// 15 points
#include <bits/stdc++.h>
using namespace std;

struct Stu{
	string id;
	int score;
	
	bool operator < (Stu s) const{
		if(score != s.score) return score > s.score;
		return id < s.id;
	}
};

struct Room{
	string id;
	int score = 0, peo = 0;
	
	bool operator < (Room r) const{
		if(peo != r.peo) return peo > r.peo;
		return id < r.id;
	}
};

struct Date{
	string id;
	int peo = 0;
	
	bool operator < (Room r) const{
		if(peo != r.peo) return peo > r.peo;
		return id < r.id;
	}
};

int main() {
	int N, M;
	map<char, set<Stu>> stu;
	map<string, Room> room;
	map<string, map<string, Room>> date;
	cin >> N >> M;
	
	while(N--){
		string id;
		int score;
		cin >> id >> score;
		string roomID =  id.substr(1, 3), datetmp =  id.substr(4, 6);

		// 类型1 
		stu[id[0]].insert({id, score});	
		
		// 类型2
		room[roomID].id = roomID;
		room[roomID].score += score;
		room[roomID].peo++;
		
		// 类型3 
		date[datetmp][roomID].id = roomID;
		date[datetmp][roomID].peo++;
	}
	
	for(int i = 1; i <= M; i++){
		int type; string obj; 
		cin >> type >> obj;
		printf("Case %d: %d %s\n", i, type, obj.c_str());
		
		if(type == 1){
			for(auto s: stu[obj[0]])
				cout << s.id << " " << s.score << endl;
		}
		else if(type == 2){
			if(room.find(obj) == room.end())cout << "NA" << endl;
			else cout << room[obj].peo << " " << room[obj].score << endl;
		}
		else{
			// 放入 set 集合排序 
			set<Room> out;
			for(auto d: date[obj]) out.insert(d.second);
			for(auto o: out)
				cout << o.id << " " << o.peo << endl;
		}
	}
}

标签:1095,PAT,score,point,int,peo,return,roomID,id
来源: https://www.cnblogs.com/Atl212/p/15321281.html