1095 解码PAT准考证 (25 point(s))
作者:互联网
-
写的时候有个几问题,刚开始以为考场的数据能够和日期的相似而共用,但是测试的时候发现,同考场的不一定同日期。所以又新建了一个结构体来存日期相关的数据。
-
测试点一、二、四。
题干太长看得有点意识模糊。写的时候只考虑了类型 2 查询无果,而没有考虑类型 1 和 3 。所以要参考类型 2 一样多加一个查询判断。
我是用下面这个测试数据才发现自己忽略了这个判断的。
-
测试点三。修改了上面的问题后剩下测试点三超时。又参考了其他文章,原来是老问题 cin cout 太慢了,改成 printf 和 scanf 即可。
#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