Football (aka soccer)

Source: Internet
Author: User

24. Football (aka soccer) score: 10/discount: 0.8the Problem

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 (five of them: 1958,196 2, 1970,199 4 and 2002 ). as our national tournament have registrteams (and even regional tournaments have registrteams also) It's a very hard task to keep track of standings with so far team S and games played!

So, your task is quite simple: write a program that matches es 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. obviusly, 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 ):

  1. Most points earned.
  2. Most wins.
  3. Most goal difference (I. e. goals scored-goals against)
  4. Most goals scored.
  5. Less games played.
  6. Lexicographic Order.
The input

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 particles 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), waiting t 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_2

For instance, the following line:

Team A#3@1#Team B

Means 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.

The output

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 shoshould the tie-breaker be the Lexicographic 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:

  • [A] = team rank
  • [B] = total points earned
  • [C] = games played
  • [D] = wins
  • [E] = ties
  • [F] = losses
  • [G] = goal difference
  • [H] = goals scored
  • [I] = goals against

There must be a single blank space between fields and a single blank line between output sets. See the sample output for examples.

Sample Input
2World Cup 1998 - Group A4BrazilNorwayMoroccoScotland6Brazil#2@1#ScotlandNorway#2@2#MoroccoScotland#1@1#NorwayBrazil#3@0#MoroccoMorocco#3@0#ScotlandBrazil#1@2#NorwaySome strange tournament5Team ATeam BTeam CTeam DTeam E5Team A#1@1#Team BTeam A#2@2#Team CTeam A#0@0#Team DTeam E#2@1#Team CTeam E#1@2#Team D
Sample output
World Cup 1998 - Group A1) 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 tournament1) 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)
 
#include<stdio.h>#include<string.h>int N,T,G,goal1,goal2;char tounament[100];void search(char a[31],char b[31]);void compositor();struct team {char name[31];int points,G_played,wins,ties,losses,scored,against;}team[30],*rank[30];void main(){int i,j,k,t;char player1[31],player2[31],c;scanf("%d",&N);getchar();for(i=0;i<N;i++){gets(tounament);scanf("%d",&T);getchar();for(j=0;j<T;j++){gets(team[j].name);rank[j]=&team[j];team[j].points=0;team[j].G_played=0;team[j].wins=0;team[j].ties=0;team[j].losses=0;team[j].scored=0;team[j].against=0;}scanf("%d",&G);getchar();for(k=0;k<G;k++){t=0;do{c=getchar();if(c=='#'||c=='@')break;elseplayer1[t++]=c;}while(1);player1[t]='\0';scanf("%d@%d",&goal1,&goal2);scanf("%c",&c);gets(player2);search(player1,player2);}compositor();printf("%s\n",tounament);for(j=0;j<T;j++){printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",j+1,rank[j]->name,rank[j]->points,rank[j]->G_played,rank[j]->wins,rank[j]->ties,rank[j]->losses,rank[j]->scored-rank[j]->against,rank[j]->scored,rank[j]->against);/*Brazil 6p, 3g (2-0-1), 3gd (6-3)*/}if(i!=N-1)printf("\n");}}void search(char a[31],char b[31]){int i;for(i=0;i<T;i++){if(!strcmp(a,team[i].name)){team[i].G_played++;team[i].scored+=goal1;team[i].against+=goal2;if(goal1>goal2){team[i].wins++;team[i].points+=3;}else{if(goal1==goal2){team[i].ties++;team[i].points++;}else{team[i].losses++;}}}if(!strcmp(b,team[i].name)){team[i].G_played++;team[i].scored+=goal2;team[i].against+=goal1;if(goal1<goal2){team[i].wins++;team[i].points+=3;}else{if(goal1==goal2){team[i].ties++;team[i].points++;}else{team[i].losses++;}}}}}void compositor(){struct team *p;int i,j,m;for(i=0;i<T-1;i++){m=i;for(j=i+1;j<T;j++){if(rank[j]->points>rank[m]->points)m=j;else{if(rank[j]->points==rank[m]->points){if(rank[j]->wins>rank[m]->wins)m=j;else{if(rank[j]->wins==rank[m]->wins){if((rank[j]->scored-rank[j]->against)>(rank[m]->scored-rank[m]->against))m=j;else{if((rank[j]->scored-rank[j]->against)==(rank[m]->scored-rank[m]->against)){if(rank[j]->scored>rank[m]->scored)m=j;else{if(rank[j]->G_played<rank[m]->G_played)m=j;else{if(rank[j]->G_played==rank[m]->G_played){if(strcmp(rank[j]->name,rank[m]->name)<0)m=j;}}}}}}}}}}if(m!=i){p=rank[m];rank[m]=rank[i];rank[i]=p;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.