[백준] Speed fines are not fine! (6763)(kotlin)
문제 설명
Many communities now have “radar” signs that tell drivers what their speed is, in the hope that they will slow down.
You will output a message for a “radar” sign. The message will display information to a driver based on his/her speed according to the following table:
km/h over the limit | Fine |
1 to 20 | $100 |
21 to 30 | $270 |
31 or above | $500 |
입력
The input will be two integers. The first line of input will be speed limit. The second line of input will be the recorded speed of the car.
출력
If the driver is not speeding, the output should be:
Congratulations, you are within the speed limit!
If the driver is speeding, the output should be:
You are speeding and your fine is $F.
where F is the amount of the fine as described in the table above.
테스트 케이스
입력 | 출력 |
---|---|
100 131 |
You are speeding and your fine is $500. |
40 39 |
Congratulations, you are within the speed limit! |
100 120 |
You are speeding and your fine is $100. |
문제 풀이1
import java.util.Scanner
fun main(args: Array<String>) = println(
(0..1).asIterable()
.map { sc.nextInt() }
.reduce { acc, i -> i - acc }
.let {
if (it > 0) {
when (it) {
in 1..20 -> "You are speeding and your fine is \$100."
in 21..30 -> "You are speeding and your fine is \$270."
else -> "You are speeding and your fine is \$500."
}
} else {
"Congratulations, you are within the speed limit!"
}
}
)
val sc = Scanner(System.`in`)