문제 출처 : https://www.acmicpc.net/problem/6841
언어 : Kotlin
문제 설명 :
Text messaging using a cell phone is popular among teenagers. The messages can appear peculiar because short forms and symbols are used to abbreviate messages and hence reduce typing.
For example, “LOL” means “laughing out loud” and “:-)” is called an emoticon which looks like a happy face (on its side) and it indicates chuckling. This is all quite a mystery to some adults.
Write a program that will continually input a short form and output the translation for an adult using the following translation table:
Short Form | Translation |
CU | see you |
:-) | I’m happy |
:-( | I’m Unhappy |
;-) | wink |
:-P | stick out my tongue |
(~.~) | sleepy |
TA | totally awesome |
CCC | Canadian Computing Competition |
CUZ | because |
TY | thank-you |
YW | you’re welcome |
TTYL | talk to you later |
입력 :
The user will be prompted to enter text to be translated one line at a time. When the short form “TTYL” is entered, the program ends. Users may enter text that is found in the translation table, or they may enter other words. All entered text will be symbols or upper case letters. There will be no spaces and no quotation marks.
출력 :
The program will output text immediately after each line of input. If the input is one of the phrases in the translation table, the output will be the translation; if the input does not appear in the table, the output will be the original word. The translation of the last short form entered “TTYL” should be output.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 128MB
입출력 예 :
입력 | 출력 |
CCC :-) SQL TTYL |
Canadian Computing Competition I’m happy SQL talk to you later |
풀이 :
혹시 틀린다면 문제에서 주어준 콤마를 잘 확인해보자. 엔터 옆의 ' 가 아니라, 특수문자인 ’ 이다.
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()
bw.appendLine(checkAndReturn(input))
bw.flush()
if (input == "TTYL") break
}
bw.close()
}
fun checkAndReturn(str: String): String {
return when (str) {
"CU" -> "see you"
":-)" -> "I’m happy"
":-(" -> "I’m unhappy"
";-)" -> "wink"
":-P" -> "stick out my tongue"
"(~.~)" -> "sleepy"
"TA" -> "totally awesome"
"CCC" -> "Canadian Computing Competition"
"CUZ" -> "because"
"TY" -> "thank-you"
"YW" -> "you’re welcome"
"TTYL" -> "talk to you later"
else -> str
}
}
'백준 > 문제' 카테고리의 다른 글
25630번: 팰린드롬 소떡소떡 (0) | 2024.05.21 |
---|---|
15886번: 내 선물을 받아줘 2 (0) | 2024.05.21 |
13419번: 탕수육 (0) | 2024.05.20 |
11121번: Communication Channels (0) | 2024.05.20 |
10384번: 팬그램 (0) | 2024.05.17 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!