문제 출처 : https://www.acmicpc.net/problem/16360
언어 : Kotlin
문제 설명 :
There are English words that you want to translate them into pseudo-Latin. To change an English word into pseudo-Latin word, you simply change the end of the English word like the following table.
English | pseudo-Latin |
-a | -as |
-i, -y | -ios |
-l | -les |
-n, -ne | -anes |
-o | -os |
-r | -res |
-t | -tas |
-u | -us |
-v | -ves |
-w | -was |
If a word is not ended as it stated in the table, put ‘-us’ at the end of the word. For example, a word “cup” is translated into “cupus” and a word “water” is translated into “wateres”.
Write a program that translates English words into pseudo-Latin words.
입력 :
Your program is to read from standard input. The input starts with a line containing an integer, n (1 ≤ n ≤ 20), where n is the number of English words. In the following n lines, each line contains an English word. Words use only lowercase alphabet letters and each word contains at least 3 and at most 30 letters.
출력 :
Your program is to write to standard output. For an English word, print exactly one pseudo-Latin word in a line.
제한 사항 :
- 시간 제한 : 0.5초
- 메모리 제한 : 512MB
입출력 예 :
입력 | 출력 |
2 toy engine |
toios engianes |
3 cup water cappuccino |
cupus wateres cappuccinos |
풀이 :
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))
repeat(readLine().toInt()) {
val sb = StringBuilder(readLine())
var last = sb.last()
if (sb.endsWith("ne")) {
sb.deleteRange(sb.lastIndex - 1, sb.length)
last = 'n'
} else {
sb.deleteAt(sb.lastIndex)
}
val newLast = when (last) {
'a' -> "as"
'i', 'y' -> "ios"
'l' -> "les"
'n' -> "anes"
'o' -> "os"
'r' -> "res"
't' -> "tas"
'u' -> "us"
'v' -> "ves"
'w' -> "was"
else -> "${last}us"
}
sb.append(newLast)
bw.appendLine(sb.toString())
bw.flush()
}
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
28702번: FizzBuzz (0) | 2024.06.03 |
---|---|
30454번: 얼룩말을 찾아라! (0) | 2024.05.31 |
3447번: 버그왕 (0) | 2024.05.31 |
11094번: 꿍 가라사대 (0) | 2024.05.30 |
1706번: 크로스워드 (0) | 2024.05.30 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!