We are the Champions

13 downloads 615 Views 10KB Size Report
We are the Champions. Input file: champs.in. Every 4 years, FIFA organizes the World Cup Tournament to determine the Soccer (Football). Champion of the ...
We are the Champions Input file: champs.in Every 4 years, FIFA organizes the World Cup Tournament to determine the Soccer (Football) Champion of the World. The tournament is divided into multiple phases. First, the teams have to participate in a round of matches against the other nations in their geographical region. Each regional tournament produces a number of qualified teams. In the "first round of the final phase," the qualified teams are divided into groups of four, and they play a round-robin tournament against the other teams in the same group. The two teams out of each group with the highest relative ranking qualify for the next phase of the tournament. You must write a program that, given the teams in each group, and the results of the round-robin matches, will determine which two teams will move on to the next phase.

Rules: The relative ranking of any pair of teams within the group is determined by the sequential application of the following rules. 1. Total points: each team is assigned 3 points for each match it won, 1 point for each match it drew, and 0 points for each match it lost. The team with the higher total points has the higher ranking. 2. Goal Differential: the sum of goals scored by the team, minus the sum of goals scored against the team, in all of the matches it played during the round. If the two teams have the same total points, the team with the higher goal differential has the higher ranking. 3. Goals scored: the number of goals scored by the team in all the matches played during this round of the tournament. If the two teams have the same total points, and goal differential, the team with the higher number of goals has the higher ranking. 4. Seed: a number reflecting the official FIFA placement of the team before the current phase of the tournament. The teams are listed in the input data set in order of their placement within each group, from first to last seed. When two teams have the same total points, goal differential, and number of goals scored, a team with lower seed has the higher ranking than a team with a higher seed.

Input: The input file will contain one or more data sets. Each data set begins with a line containing the group name, followed by the name of the 4 teams in the group. This line has the format: Group : ,,,

There is a single space after the word group and the colon. The length of this line is at most 80 characters. The group name, denoted by , is a sequence of one or more characters. Each team name, denoted by (where N is 1, 2, 3, or 4), is a sequence of alphabetic characters ('a'-'z', 'A'-'Z') that begins with a letter and includes only alphabetical characters, and embedded spaces.

This is followed by 6 lines, each describing a match result for each pairing of teams in the form: :

There is exactly one space between the team name and its score. The s are integers in the range [0..42]. There will be one blank line after each data set. The end of input is marked by end-of-file.

Output: For each data set, the output should begin with a line of the form “Group :”, where is as found in the input data set. This should be followed by two lines listing the two teams that will pass to the next round in the following format: (,,,)

where is the team’s total points, is the team’s signed (i.e., starting with + or –, with 0 being positive) goal differential, are the team’s scored points, and are the points scored against the team. The two teams must be listed in the order of their ranking at the end of the round-robin round (the team that ranks first before the team that ranks second). The output for each data set should be followed by a blank line.

Sample Input: Group A 0:0 C 0:0 B 0:0 D 0:0 A 0:0 D 0:0

1 first example: A,B,C,D B D C A C B

Group A: Senegal,France,Germany,Brazil France 0:1 Senegal Germany 0:0 Brazil Senegal 2:2 Germany Brazil 1:0 France Brazil 1:2 Senegal France 1:1 Germany

Output Corresponding to Sample Input: Group 1 first example: A (3,+0,0,0) B (3,+0,0,0) Group A: Senegal (7,+2,5,3) Brazil (4,+0,2,2) Group Odd Name: Genoa (9,+4,6,2) Juventus (2,-1,3,4)

Group Odd Name: Genoa,Sampdoria,Int Milano,Juventus Genoa 3:1 Sampdoria Int Milano 1:1 Juventus Juventus 1:2 Genoa Sampdoria 0:0 Int Milano Genoa 1:0 Int Milano Sampdoria 1:1 Juventus