Problem A: Football (aka Soccer) |
Football the most popular sport in the world (americans insist to call it "Soccer", but we will call it "Football"). As everyone knows, Brasil is the country that have most World Cup titles (four of them: 1958, 1962, 1970 and 1994). As our national tournament have many teams (and even regional tournaments have many teams also) it's a very hard task to keep track of standings with so many teams and games played!
So, your task is quite simple: write a program that receives the tournament name, team names and games played and outputs the tournament standings so far.
A team wins a game if it scores more goals than its oponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss.
Teams are ranked according to these rules (in this order):
The first line of input will be an integer N in a line alone (0 < N < 1000). Then, will follow N tournament descriptions. Each one begins with the tournament name, on a single line. Tournament names can have any letter, digits, spaces etc. Tournament names will have length of at most 100. Then, in the next line, there will be a number T (1 < T <= 30), which stands for the number of teams participating on this tournament. Then will follow T lines, each one containing one team name. Team names may have any character that have ASCII code greater than or equal to 32 (space), except for '#' and '@' characters, which will never appear in team names. No team name will have more than 30 characters.
Following to team names, there will be a non-negative integer G on a single line which stands for the number of games already played on this tournament. G will be no greater than 1000. Then, G lines will follow with the results of games played. They will follow this format:
team_name_1#goals1@goals2#team_name_2For instance, the following line:
Team A#3@1#Team BMeans that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1. All goals will be non-negative integers less than 20. You may assume that there will not be inexistent team names (i.e. all team names that appear on game results will have apperead on the team names section) and that no team will play against itself.
For each tournament, you must output the tournament name in a single line. In the next T lines you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexographic order, it must be done case insenstive. The output format for each line is shown bellow:
[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])Where:
2 World Cup 1998 - Group A 4 Brazil Norway Morocco Scotland 6 Brazil#2@1#Scotland Norway#2@2#Morocco Scotland#1@1#Norway Brazil#3@0#Morocco Morocco#3@0#Scotland Brazil#1@2#Norway Some strange tournament 5 Team A Team B Team C Team D Team E 5 Team A#1@1#Team B Team A#2@2#Team C Team A#0@0#Team D Team E#2@1#Team C Team E#1@2#Team D
World Cup 1998 - Group A 1) Brazil 6p, 3g (2-0-1), 3gd (6-3) 2) Norway 5p, 3g (1-2-0), 1gd (5-4) 3) Morocco 4p, 3g (1-1-1), 0gd (5-5) 4) Scotland 1p, 3g (0-1-2), -4gd (2-6) Some strange tournament 1) Team D 4p, 2g (1-1-0), 1gd (2-1) 2) Team E 3p, 2g (1-0-1), 0gd (3-3) 3) Team A 3p, 3g (0-3-0), 0gd (3-3) 4) Team B 1p, 1g (0-1-0), 0gd (1-1) 5) Team C 1p, 2g (0-1-1), -1gd (3-4)
© 2001 Universidade do Brasil (UFRJ). Internal Contest 2001.
// 10194 - Football (aka Soccer).cpp : 定义控制台应用程序的入口点。 // #include <vector> #include <string> #include <algorithm> #include <iostream> #include<cstring> #include <set> #include <map> #include <cctype> #include <time.h> using namespace std; class Team{ public: Team(): b_earned(0),c_played_num(0),d_wins(0),e_ties(0), f_losses(0),g_diff(0), h_scored(0), i_aginst(0){} string name; int b_earned; int c_played_num; int d_wins; int e_ties; int f_losses; int g_diff; int h_scored; int i_aginst; }; string nameToUpper(const string &name) { string tname; for(size_t i=0;i<name.size();++i) tname.push_back(toupper(name[i])); return tname; } bool operator<(const Team &team1,const Team &team2){ if(team1.b_earned!=team2.b_earned) return team1.b_earned<team2.b_earned; if(team1.d_wins!=team2.d_wins) return team1.d_wins<team2.d_wins ; if(team1.g_diff!=team2.g_diff) return team1.g_diff<team2.g_diff; if(team1.h_scored!=team2.h_scored) return team1.h_scored<team2.h_scored; if(team1.c_played_num!=team2.c_played_num) return team1.c_played_num>team2.c_played_num; string t1_name=nameToUpper(team1.name); string t2_name=nameToUpper(team2.name); return t1_name>t2_name; } void saveTeam(map<string,Team *> &team_map,string &t_name,int t_score,int t_played,int t_against,int t_diff,int t_tie,int t_loss,int t_wins) { Team *team=team_map[t_name]; team->h_scored+=t_score; team->c_played_num+=t_played; team->d_wins+=t_wins; team->e_ties+=t_tie; team->f_losses+=t_loss; team->g_diff+=t_diff; team->i_aginst+=t_against; } void countPoints(map<string,Team *> &team_map) { for(auto &p:team_map){ auto team=p.second; team->b_earned=team->d_wins*3+team->e_ties; } } int main() { int n; cin>>n; cin.ignore(); // double time_1=(double)clock()/CLOCKS_PER_SEC; while(n){ // cin.sync(); map<string,Team *> team_map; // vector<Team *> v; string tournament_name; getline(cin,tournament_name); cout<<tournament_name<<endl; int m; cin>>m; cin.ignore(); // cout<<tournament_name<<endl; while(m--){ // cin.sync(); string team_name; team_name.reserve(40); getline(cin,team_name); Team *team=new Team; team->name=team_name; team_map[team_name]=team; //v.push_back(team); } int games_time; cin>>games_time; cin.ignore(); while(games_time--){ // cin.sync(); string s; s.reserve(100); getline(cin,s); size_t pos_1=s.find_first_of('#'); size_t pos_2=s.find_first_of('@',pos_1+1); string t1_name=s.substr(0,pos_1); int t1_scores=stoi(s.substr(pos_1+1,pos_2-pos_1-1)); size_t pos_3=s.find_first_of('#',pos_2+1); int t2_scores=stoi(s.substr(pos_2+1,pos_3-pos_2-1)); string t2_name=s.substr(pos_3+1,s.size()-1-pos_3); int t1_played=0,t1_against=0,t1_diff=0,t1_tie=0,t1_loss=0,t1_wins=0; int t2_played=0,t2_against=0,t2_diff=0,t2_tie=0,t2_loss=0,t2_wins=0; t1_played=1; t1_against=t2_scores; t1_diff=t1_scores-t1_against; if(t1_scores<t2_scores) {t1_loss=1;t2_wins=1;} else if(t1_scores>t2_scores){ t1_wins=1;t2_loss=1;} else {t1_tie=1;t2_tie=1;} t2_played=1; t2_against=t1_scores; t2_diff=t2_scores-t2_against; saveTeam(team_map,t1_name, t1_scores, t1_played, t1_against, t1_diff, t1_tie, t1_loss, t1_wins); saveTeam(team_map,t2_name, t2_scores, t2_played, t2_against, t2_diff, t2_tie, t2_loss, t2_wins); } countPoints(team_map); set<Team> s_set; for(auto p:team_map){ s_set.insert(*p.second); delete p.second; } //sort(v.begin(),v.end()); int rank=1; //cout<<tournament_name<<endl; for(auto iter=s_set.rbegin();iter!=s_set.rend();++iter){ cout<<rank++<<") "<<iter->name<<" "<<iter->b_earned<<"p, " <<iter->c_played_num<<"g ("<<iter->d_wins<<"-" <<iter->e_ties<<"-"<<iter->f_losses<<"), " <<iter->g_diff<<"gd ("<<iter->h_scored<<"-" <<iter->i_aginst<<")"<<endl; } n-=1; if(n) cout<<endl; } // double time_2=(double)clock()/CLOCKS_PER_SEC; // cout<<"-------------------"<<time_2-time_1<<"------------------"<<endl; return 0; } /* 2 World Cup 1998 - Group A 4 Brazil Norway Morocco Scotland 6 Brazil#12@11#Scotland Norway#2@2#Morocco Scotland#1@1#Norway Brazil#3@0#Morocco Morocco#3@0#Scotland Brazil#1@2#Norway Some strange tournament 5 Team A Team B Team C Team D Team E 5 Team A#1@1#Team B Team A#2@2#Team C Team A#0@0#Team D Team E#2@1#Team C Team E#1@2#Team D */