-
Notifications
You must be signed in to change notification settings - Fork 1
/
1095.cpp
135 lines (134 loc) · 3.11 KB
/
1095.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
struct node{
int type,pos,id,date,score;
};
struct nodes{
int pos,cnt;
};
bool cmp1(node a,node b){
if(a.type==b.type){
if(a.score==b.score){
if(a.pos==b.pos){
if(a.date==b.date){
return a.id<b.id;
}
else{
return a.date<b.date;
}
}
else{
return a.pos<b.pos;
}
}
else{
return a.score>b.score;
}
}
return a.type>b.type;
}
bool cmp2(nodes a,nodes b){
if(a.cnt==b.cnt){
return a.pos<b.pos;
}
return a.cnt>b.cnt;
}
int main(){
node arr[10010]={0};
int n,m,i,j,ca=1;
cin>>n>>m;
getchar();
for(i=0;i<n;i++){
char type;
scanf("%c%3d%6d%3d %d",&type,&arr[i].pos,&arr[i].date,&arr[i].id,&arr[i].score);
getchar();
//cout<<"--- "<<type<<endl;
if(type=='T'){
arr[i].type=1;
}
else if(type=='A'){
arr[i].type=2;
}
else{
arr[i].type=3;
}
}
for(j=0;j<m;j++){
int type;
cin>>type;
if(type==1){
char in;
cin>>in;
int fi=0;
if(in=='T'){
fi=1;
}
if(in=='A'){
fi=2;
}
if(in=='B'){
fi=3;
}
int cnt=0;
sort(arr,arr+n,cmp1);
printf("Case %d: %d %c\n",ca++,type,in);
for(i=0;i<n;i++){
if(arr[i].type==fi){
printf("%c%03d%06d%03d %d\n",in,arr[i].pos,arr[i].date,arr[i].id,arr[i].score);
cnt++;
}
}
if(cnt==0){
printf("NA\n");
}
}
else if(type==2){
int pos;
cin>>pos;
int pc=0,sc=0;
for(i=0;i<n;i++){
if(arr[i].pos==pos){
pc++;
sc+=arr[i].score;
}
}
printf("Case %d: %d %d\n",ca++,type,pos);
if(pc==0){
printf("NA\n");
}
else{
printf("%d %d\n",pc,sc);
}
}
else{
int date;
cin>>date;
nodes rec[1010]={0};
int cnt=0;
for(i=0;i<n;i++){
if(arr[i].date==date){
rec[arr[i].pos].cnt++;
rec[arr[i].pos].pos=arr[i].pos;
}
}
sort(rec,rec+1000,cmp2);
printf("Case %d: %d %06d\n",ca++,type,date);
for(int i=0;i<1000;i++){
if(rec[i].cnt!=0){
printf("%03d %d\n",rec[i].pos,rec[i].cnt);
cnt++;
}
}
if(cnt==0){
printf("NA\n");
}
}
}
system("pause");
return 0;
}