-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEASYPIE-1191449-src.cpp
104 lines (97 loc) · 1.8 KB
/
EASYPIE-1191449-src.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
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
class sub{
public:
int t, count;
string s;
char st;
sub *l, *r;
sub(){l=0; r=0; st='R'; count=0;}
sub(int tt, string ss, char stt){t=tt; s=ss; st=stt; count=1; l=0; r=0;}
};
class avg{
public:
int total_submissions, total_teams, total_time;
avg(){}
avg(int a, int b, int c){total_submissions=a; total_teams=b; total_time=c;}
};
vector<sub *> v(9);
stack<sub *> s;
void insert(int t, string s, char c2, int i){
if(v[i]==0){
v[i]=new sub(t, s, c2);
return;
}
sub *tp=v[i];
while(1){
if(s.compare(tp->s)==0){
if(tp->st=='R')
tp->count++;
if(c2=='A' && tp->st=='R'){
tp->t=t;
tp->st='A';
}
return;
}
else if(s.compare(tp->s)<0 && tp->l!=0)
tp=tp->l;
else if(s.compare(tp->s)<0){
tp->l=new sub(t, s, c2);
return;
}
else if(s.compare(tp->s)>0 && tp->r!=0)
tp=tp->r;
else{
tp->r=new sub(t, s, c2);
return;
}
}
}
avg compute(int i){
int total_time=0, total_submissions=0, total_teams=0;
sub *tp=v[i];
while(1){
while(tp!=0){
if(tp->st=='A'){
total_time+=tp->t;
total_submissions+=tp->count;
total_teams++;
}
s.push(tp);
tp=tp->l;
}
if(!s.empty()){
tp=s.top();
tp=tp->r;
s.pop();
}
else
break;
}
return avg(total_submissions, total_teams, total_time);
}
int main(){
int test, n, t;
string s;
char c1, c2;
avg tp;
scanf("%d", &test);
while(test--){
scanf("%d", &n);
for(int i=0; i<9; i++)
v[i]=0;
for(int i=0; i<n; i++){
cin>>t>>s>>c1>>c2;
insert(t, s, c2, c1-'A');
}
for(int i=0; i<9; i++){
tp=compute(i);
if(tp.total_teams==0)
printf("%c 0\n", 'A'+i);
else
printf("%c %d %.2f %.2f\n", 'A'+i, tp.total_teams, (float)tp.total_submissions/tp.total_teams, (float)tp.total_time/tp.total_teams);
}
}
}