TopCoder problem "SoccerCommentator" used in TCHS07 Semifinal (Division I Level Two)



Problem Statement

    A play-off round between 2 teams in most soccer competitions consists of two games. Each team hosts one of these two games, and the team that scores more total goals advances. If both teams have scored the same total number of goals, the team who have scored more away goals advances. If both teams score the same total number of goals, the team that scored more away goals advances. (An "away" goal is one that is scored in a game hosted by the other team.) If both teams score the same number of away goals, they must go into overtime.

You will be given the score of the first game and the current score of the second game (still in progress). Each score will be a String formatted as "G1:G2" (quotes for clarity), where G1 is the number of goals scored by the first team, and G2 is the number of goals scored by the second team. You will also be given firstGameHost, which is equal to 1 if the first game was hosted by team 1, and 2 otherwise. Return the number of additional goals the first team must score in the second game to advance without going into overtime.
 

Definition

    
Class:SoccerCommentator
Method:goalsToWin
Parameters:String, String, int
Returns:int
Method signature:int goalsToWin(String score1, String score2, int firstGameHost)
(be sure your method is public)
    
 

Constraints

-score1 and score2 will each be formatted as two digits separated by ':'.
-All digits in score1 and score2 will be between 0 and 5, inclusive.
-firstGameHost will be equal to 1 or 2.
 

Examples

0)
    
"0:0"
"0:0"
1
Returns: 1
Now is draw. The first team must score goal to advance without going into overtime.
1)
    
"0:2"
"0:3"
1
Returns: 5
5 away goals is enough to advance.
2)
    
"0:2"
"0:3"
2
Returns: 6
The first team scores 0 away goals, thats why now it is neccesary to score 6 goals.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7770

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10763&pm=7770

Writer:

VitalyGoldstein

Testers:

PabloGilberto , brett1479 , Cosmin.ro , Olexiy

Problem categories:

Simple Math