- 8 4
- B123180908127 99
- B102180908003 86
- A112180318002 98
- T107150310127 62
- A107180908108 100
- T123180908010 78
- B112160918035 88
- A107180908021 98
- 1 A
- 2 107
- 3 180908
- 2 999
- Case 1: 1 A
- A107180908108 100
- A107180908021 98
- A112180318002 98
- Case 2: 2 107
- 3 260
- Case 3: 3 180908
- 107 2
- 123 2
- 102 1
- Case 4: 2 999
- NA
- #include
- using namespace std;
- void input(int command); // 查询操作
- vector
int>> top[3]; // 各个级别储存 0-T,1-A,2-B - map<int,pair<long,long>> room; // 考场号 -> 考场人数 and 总得分
- map<long,vector<int>> findRoom; // 日期 -> 该日期拥有的考场号
- map
long,int>,int> findNum; // 日期+考场号 -> 当天该考场人数 - bool cmp(const pair
int >& x,const pairint >& y){ // 排序PAB各个级别的排名 - if(x.second!=y.second) return x.second>y.second;
- return x.first < y.first;
- }
- bool cmp1(pair<int,int> x,pair<int,int> y){ // 排序查询3操作
- if(x.second!=y.second) return x.second>y.second;
- return x.first < y.first;
- }
- int main()
- {
- string id;
- int N,M,n,roomId;
- cin >> N >> M;
-
- while (N--){
- cin >> id >> n;
- // 查询1 录入
- if(id[0]=='T') top[0].emplace_back(id,n);
- else if(id[0]=='A') top[1].emplace_back(id,n);
- else top[2].emplace_back(id,n);
- // 查询2 录入
- roomId = (id[1]-48)*100+(id[2]-48)*10+id[3]-48;
- room[roomId].first++;
- room[roomId].second+=n;
- // 查询3 录入
- long day = 0;
- for(int z=4;z<10;z++) day = day*10+id[z]-48;
- if(0==findNum[pair<long,int>(day,roomId)]++) findRoom[day].push_back(roomId);
- }
-
- for(auto & z : top) sort(z.begin(),z.end(),cmp);
-
- for(int z=1;z<=M;z++){
- cout << "Case " << z << ": ";
- cin >> n;
- input(n);
- }
- return 0;
- }
- void input(int command)
- {
- long day; // 数据读入使用
- char level; // 数据读入使用
- bool flag = true; // 判断有无输出
- if(command==1)
- {
- cin >> level; cout << command << " " << level << endl;
- day = level=='T'? 0 : level=='A'? 1 : 2;
- for(const auto& x:top[day]) cout << x.first << " " << x.second << endl;
- if(top[day].empty()) flag = false;
- }
- else if(command==2)
- {
- cin >> day; cout << command << " " << day << endl;
- if(room[day].first>0) cout << room[day].first << " " << room[day].second << endl;
- else flag = false;
- }
- else
- {
- cin >> day;
- printf("%ld %06ld\n",command,day);
- vector
int,int>> box; - for(int x:findRoom[day]){
- box.emplace_back(x,findNum[pair<long,int>(day,x)]);
- }
- sort(box.begin(),box.end(),cmp1);
- if(box.empty()) flag = false;
- else for(auto x:box) cout << x.first << " " << x.second << endl;
- }
-
- if(!flag) cout << "NA" << endl;
- }