문제 출처 : https://www.acmicpc.net/problem/11367
언어 : Kotlin
문제 설명 :
Little hobbitses go to hobbit school in the Shire. They just finished a course, which involved tea-making, meal-eating, nap-taking, and gardening. Based on the following grading scale, assign each hobbit a letter grade based on their final numerical course grade.
- A+: 97-100
- A: 90-96
- B+: 87-89
- B: 80-86
- C+: 77-79
- C: 70-76
- D+: 67-69
- D: 60-66
- F: 0-59
입력 :
The input will begin with a single line containing just a whole number, n, of the number of hobbits in the class, followed by n lines in the form a b, where a is the hobbit’s name (only alphabetical characters) and b is the hobbit’s grade, given as a whole number. The length of hobbit's name is less than 10.
출력 :
For each test case, print out a list of every hobbits name and letter grade, each on its own line. There should be no additional white space following test cases.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 256MB
입출력 예 :
입력 | 출력 |
5 Bilbo 13 Sam 90 Pippin 78 Frodo 97 Merry 70 |
Bilbo F Sam A Pippin C+ Frodo A+ Merry C |
풀이 :
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
val bw = BufferedWriter(OutputStreamWriter(System.out))
val n = readLine().toInt()
repeat(n) {
val (name, score) = readLine().split(" ")
bw.write("$name ${getGrade(score.toInt())}")
if (it < n) bw.append("\n")
}
bw.flush()
bw.close()
}
fun getGrade(score: Int): String {
return when (score) {
in 97 .. 100 -> "A+"
in 90 .. 96 -> "A"
in 87 .. 89 -> "B+"
in 80 .. 86 -> "B"
in 77 .. 79 -> "C+"
in 70 .. 76 -> "C"
in 67 .. 69 -> "D+"
in 60 .. 66 -> "D"
else -> "F"
}
}
'백준 > 문제' 카테고리의 다른 글
12780번: 원피스 (0) | 2024.04.15 |
---|---|
3107번: IPv6 (0) | 2024.04.12 |
14726번: 신용카드 판별 (0) | 2024.04.12 |
4597번: 패리티 (0) | 2024.04.11 |
10266번: 시계 사진들 (0) | 2024.04.11 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!