Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss10194 - | Accepted | C++11 | 0.000 | 0.000 | 1040 | 28 secs ago |
Suggest:
- Use STL map + Struct (team football) + Sort by compare function (ranking)
#include<bits/stdc++.h>
using namespace std;
string s, fifa;
int t, m, n;
struct team{
int point;
int win;
int lose;
int tie;
int goal_against;
int goal_scored;
int less_game;
string name;
string name_origin;
};
bool cmp(team x, team y){
if (x.point > y.point) return true;
if (x.point == y.point){
if (x.win > y.win) return true;
if (x.win == y.win){
if (x.goal_scored - x.goal_against > y.goal_scored - y.goal_against) return true;
if (x.goal_scored - x.goal_against == y.goal_scored - y.goal_against){
if (x.goal_scored > y.goal_scored) return true;
if (x.goal_scored == y.goal_scored){
if (x.less_game < y.less_game) return true;
if (x.less_game == y.less_game ){
string team1 = "", team2 = "";
for(auto val:x.name) team1 += tolower(val);
for(auto val:y.name) team2 += tolower(val);
return (team1 < team2);
}
}
}
}
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t; cin.ignore();
while(t--){
getline(cin, fifa);
cin >> n; cin.ignore();
unordered_map<string, team> M;
for(int i=0; i<n; i++){
getline(cin, s);
M[s].point= 0;
M[s].win= 0;
M[s].lose= 0;
M[s].tie= 0;
M[s].goal_against= 0;
M[s].goal_scored= 0;
M[s].less_game= 0;
M[s].name = s;
}
cin >> m; cin.ignore();
for(int i=0; i<m; i++){
getline(cin, s);
s+='#';
string team1="", goal1="", goal2="", team2="";
int kind = 1;
for(int i=0; s[i]; i++){
if (s[i]=='#') {kind++; continue;}
if (s[i]=='@') {kind++; continue;}
if (kind==1) team1 += s[i];
if (kind==2) goal1 += s[i];
if (kind==3) goal2 += s[i];
if (kind==4) team2 += s[i];
}
int g1 = stoi(goal1);
int g2 = stoi(goal2);
M[team1].name = team1;
M[team1].goal_scored += g1;
M[team1].goal_against += g2;
M[team1].point += (g1 > g2 ? 3 : 0);
M[team1].point += (g1 == g2 ? 1 : 0);
M[team1].win += (g1 > g2 ? 1 : 0);
M[team1].less_game += 1;
M[team1].lose += (g1 < g2 ? 1 : 0);
M[team1].tie += (g1 == g2 ? 1 : 0);
M[team2].name = team2;
M[team2].goal_scored += g2;
M[team2].goal_against += g1;
M[team2].point += (g2 > g1 ? 3 : 0);
M[team2].point += (g2 == g1 ? 1 : 0);
M[team2].win += (g2 > g1 ? 1 : 0);
M[team2].less_game += 1;
M[team2].lose += (g2 < g1 ? 1 : 0);
M[team2].tie += (g2 == g1 ? 1 : 0);
}
vector<team> ranking;
for(auto it=M.begin(); it!=M.end(); it++)
ranking.push_back(it->second);
sort(ranking.begin(), ranking.end(), cmp);
cout<<fifa<<"\n";
int rank= 0;
for(auto x:ranking)
cout<<++rank<<") "<<x.name<<" "<<x.point<<"p, "<<x.less_game<<"g ("<<x.win<<"-"<<x.tie<<"-"<<x.lose<<"), "<<x.goal_scored-x.goal_against<<"gd ("<<x.goal_scored<<"-"<<x.goal_against<<")"<<"\n";
if (t) cout<<"\n";
}
}
No comments:
Post a Comment