5358번: Football Team백준/문제2024. 4. 26. 13:22
Table of Contents
문제 출처 : https://www.acmicpc.net/problem/5358
언어 : Kotlin
문제 설명 :
The PLU football coach must submit to the NCAA officials the names of all players that will be competing in NCAA Division II championship game. Unfortunately his computer keyboard malfunctioned and interchanged the letters ‘i’ and ‘e’. Your job is to write a program that will read all the names and print the names with the correct spelling.
입력 :
The file contains a list of names, and each name will be on a separate line.
출력 :
Print the same list of names with every ‘i’ replaced with an ‘e’, every ‘e’ replaced with an ‘i’, every ‘I’ replaced with an ‘E’, and every ‘E’ replaced with an ‘I’.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 128MB
입출력 예 :
입력 | 출력 |
Alan Pagi John Hiesman Justen Forsitt Phel Semms Tem Tibow Marshawn Lynch Lion Washengton |
Alan Page John Heisman Justin Forsett Phil Simms Tim Tebow Marshawn Lynch Leon Washington |
풀이 :
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))
var input: String?
while (true) {
input = readLine()
val sb = StringBuilder()
if (input.isNullOrEmpty()) break
for (i in input) {
val cur = Pair(i.lowercaseChar(), if (i.isLowerCase()) 0 else 1)
when (cur.first) {
'i' -> sb.append(if (cur.second > 0) "E" else "e")
'e' -> sb.append(if (cur.second > 0) "I" else "i")
else -> sb.append(i)
}
}
bw.appendLine(sb.toString())
}
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
9494번: Text Roll (0) | 2024.04.29 |
---|---|
15351번: 인생 점수 (0) | 2024.04.29 |
29766번: DKSH 찾기 (0) | 2024.04.26 |
28432번: 끝말잇기 (0) | 2024.04.26 |
10205번: 헤라클레스와 히드라 (0) | 2024.04.24 |
@스몰스테핑 :: 작은 발걸음
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!