-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path10698.cpp
145 lines (126 loc) · 3.96 KB
/
10698.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
135
136
137
138
139
140
141
142
143
144
145
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define leapYear(year) (((year%4==0)&&(year%100!=0))||(year%400==0))
#define validMove(x,y) ((x>=0 && x<row) && (y>=0 && y<col))
#define mod(n,m) (!(n%m))
#define bit(n,m) (n&m?1:0)
#define REP(i,a) for(__typeof(a) i=0;i<a;i++)
#define FOR(i,a,b) for(__typeof(a) i=a;i<=b;i++)
#define SET(t) memset((t),0,sizeof(t))
#define INF 1000000
#define LIMIT 11
#define MASK 64
#define SIZE 26
typedef long long int int64;
typedef struct {
int x,y;
}Point;
bool compare(int a,int b) {
return a<b;
}
using namespace std;
int fx[]={0,0,1,-1,-1,1,-1,1}; // eje x
int fy[]={1,-1,0,0,1,1,-1,-1}; // eje y
struct TEAM { // crea estructuras tipo TEAM
string name,lower_name;
int points,played,scored,against;
float percentage;
TEAM() {
name="";
points=played=scored=against=0; //las rellena
percentage=0.0;
}
void into_lower() {
REP(i,name.size()) {
lower_name+=tolower(name[i]);
}
}
bool operator < (const TEAM& b) const {
if(points!=b.points) return points>b.points;
if((scored-against)!=(b.scored-b.against)) return (scored-against)>(b.scored-b.against);
if(scored!=b.scored) return scored>b.scored;
return lower_name<b.lower_name;
}
};
int main() {
int t,m;
bool flag=true;
while(cin>>t>>m) {
if(!(t+m)) break;
if(flag) {
flag=false;
} else printf("\n");
vector<TEAM> team_list;
map<string,int> mapping;
REP(i,t) {
string name;
cin >> name;
mapping[name]=i;
TEAM temp;
temp.name=name;
temp.into_lower();
team_list.push_back(temp);
}
string team1,team2;
char hyphen;
int goal1,goal2;
REP(i,m) {
cin >> team1 >> goal1 >> hyphen >> goal2 >> team2;
team_list[mapping[team1]].played++;
team_list[mapping[team1]].scored+=goal1;
team_list[mapping[team1]].against+=goal2;
team_list[mapping[team1]].points+=((goal1>goal2?3:0)+(goal1==goal2?1:0));
team_list[mapping[team2]].played++;
team_list[mapping[team2]].scored+=goal2;
team_list[mapping[team2]].against+=goal1;
team_list[mapping[team2]].points+=((goal1<goal2?3:0)+(goal1==goal2?1:0));
}
sort(team_list.begin(),team_list.end());
REP(i,team_list.size()) {
if(team_list[i].played==0) continue;
int te,mp;
te=team_list[i].played;
mp=team_list[i].points;
team_list[i].percentage=(100.00*mp)/(te*3);
}
int rank=0;
REP(i,team_list.size()) {
int scored,against,diff;
scored=team_list[i].scored,against=team_list[i].against;
diff=scored-against;
if(i==0) {
rank=i+1;
printf("%2d.",rank);
} else if(team_list[i].points!=team_list[i-1].points || (team_list[i].scored-team_list[i].against)!=(team_list[i-1].scored-team_list[i-1].against) || team_list[i].scored!=team_list[i-1].scored) {
rank=i+1;
printf("%2d.",rank);
} else {
printf(" ");
}
printf("%16s%4d%4d%4d%4d%4d",team_list[i].name.c_str(),team_list[i].points,team_list[i].played,scored,against,diff);
if(team_list[i].played==0) {
printf("%7s\n","N/A");
continue;
}
printf("%7.2f\n",team_list[i].percentage);
}
}
return 0;
}