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;

}


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

반응형