Sunday, July 31, 2016

TCS Code Vita Season-5 Round-1 set-1 Program-6

Problem : Football League Table

Statement :
 

All major football leagues have big league tables. Whenever a new match is played, the league table is updated to show the current rankings (based on Scores, Goals For (GF), Goals Against (GA)). Given the results of a few matches among teams, write a program to print all the names of the teams in ascending order (Leader at the top and Laggard at the bottom) based on their rankings.
 

Rules: :
 
1.    A win results in 2 points, a draw results in 1 point and a loss is worth 0 points.
2.    The team with most goals in a match wins the match.
3.    Goal Difference (GD) is calculated as Goals For (GF) - Goals Against (GA)
4.    Ranking is decided as follows
1.    Team with maximum points is ranked 1 and minimum points is placed last
2.    Ties are broken as follows
1.    Teams with same points are ranked according to Goal Difference(GD).
2.    If Goal Difference(GD) is same, then team with higher Goals For is ranked ahead
3.    If GF are same, the teams should be at the same rank but they should be printed in case-insensitive alphabetic according of the team names.
5.    Teams can play maximum of two matches against each other - Home and Away matches respectively
6.    More than 2 matches of same teams, should be considered as Invalid Input
7.    A team can't play matches against itself, hence if team names are same for a given match, it should be considered Invalid Input



Input Format: 

First line of input will contain number of teams (N)
Second line contains names of the teams (Na) delimited by a whitespace character
 
Third line contains number of matches (M) for which results are available
Next M lines contain a match information tuple {T1 T2 S1 S2}, where tuple is comprised of the following information
  • T1 - Name of the first team
  • T2 - Name of the second team
  • S1 - Goals scored by the first team
  • S2 - Goals scored by the second team



Output Format: 

Team names in order of their rankings, one team per line
OR
Print "Invalid Input" where appropriate.
 
Constraints:
1.    0<N<=10,000
2.    0<=S1,S2


Example: 

Consider 5 teams Spain, England, France, Italy and Germany with the following fixtures:
 

Match 1: Spain vs. England (3-0)
 
(Spain gets 2 points, England gets 0)
Match 2: England vs. France (1-1)
 
(England gets 1 point, France gets 1)
 
Match 3: Spain vs. France (0-2)
(Spain gets 0 points, France gets 2)
 
 
Table 1. Points Table after 3 matches

Since, Italy and Germany are tied for points, goals difference is checked. Both have same, so, Goals For is checked. Since both are same. Germany and Italy share the 4
th rank. Since Germany appears alphabetically before Italy, Germany should be printed before Italy. 

Then the final result is:
France
Spain
England
Germany
Italy
 


Sample Input and Output
SNo.
Input
Output
1

5
Spain England France Italy Germany
3
Spain England 3 0
England France 1 1
Spain France 0 2

France
Spain
England
Germany
Italy
2

5
Spain England France Italy Germany
3
Spain England 3 0
England France 1 1
Spain Spain 0 2

Invalid Input

Description: https://www.tcscodevita.com/CodevitaV5/images/continent1.png
 
Output:
Island 1: 593
Island 2: 98
Number of continents: 2
 

Description: https://www.tcscodevita.com/CodevitaV5/images/continent2.png
 
Output:
Island 1: 593
Island 2: 98
Number of continents: 2
 

Example 2: 

Description: https://www.tcscodevita.com/CodevitaV5/images/continent3.png
 
Output:
Island 1: 805
Island 2: 68
Number of continents: 2
 

Contact Form

Name

Email *

Message *