알고리즘/codefights

14>tennisSet

Diademata 2019. 2. 24. 13:27
반응형

In tennis, the winner of a set is based on how many games each player wins. The first player to win 6 games is declared the winner unless their opponent had already won 5 games, in which case the set continues until one of the players has won 7 games.


Given two integers score1 and score2, your task is to determine if it is possible for a tennis set to be finished with a final score of score1 : score2. 


code>>


bool tennisSet(int score1, int score2) {

if (score1 == 7 || score2 == 7)

return score1 == 7 && (score2 == 5 || score2 == 6) || score2 == 7 && (score1 == 5 || score2 == 6);

return score1 < 5 && score2 == 6 || score2 < 5 && score1 == 6;

}


테니스 룰을 몰라서 테스트 케이스 열어서 어거지로 맞춤

반응형

'알고리즘 > codefights' 카테고리의 다른 글

16>metroCard  (0) 2019.02.24
15>willYou  (0) 2019.02.24
13>arithmeticExpression  (0) 2018.05.20
12>isInfiniteProcess  (0) 2018.05.19
11>extraNumber  (0) 2018.05.19