[백준] Tournament Selection (14038)(kotlin)
문제 설명
Each player in a tournament plays six games. There are no ties. The tournament director places the players in groups based on the results of games as follows:
- if a player wins 5 or 6 games, they are placed in Group 1;
- if a player wins 3 or 4 games, they are placed in Group 2;
- if a player wins 1 or 2 games, they are placed in Group 3;
- if a player does not win any games, they are eliminated from the tournament.
Write a program to determine which group a player is placed in
입력
The input consists of six lines, each with one of two possible letters: W (to indicate a win) or L (to indicate a loss).
출력
The output will be either 1, 2, 3 (to indicate which Group the player should be placed in) or -1 (to indicate the player has been eliminated).
테스트 케이스
입력 | 출력 |
---|---|
W L W W L W |
2 |
L L L L L L |
-1 |
문제 풀이1
import java.util.Scanner
fun main(args: Array<String>) = println(
(0 until 6)
.map { sc.next() }
.count { it == "W" }
.let {
when (it) {
in 5..6 -> 1
in 3..4 -> 2
in 1..2 -> 3
else -> -1
}
}
)
val sc = Scanner(System.`in`)