문제 출처 : https://www.acmicpc.net/problem/4072
언어 : Kotlin
문제 설명 :
A nasty virus has infected my computer. Its effect has been to attack all my text files and reverse every word in them. Your job in this problem is to write the code to restore my text files to their original condition.
As far as the virus was concerned, a word was any sequence of characters that ended with a space or an end of line character. You will see what I mean when I tell you that the first line in one of my files was:
Get ready for the New Zealand Programming Contest.
The virus turned this into:
teG ydaer rof eht weN dnalaeZ gnimmargorP .tsetnoC
See how it included the full stop with ‘Contest’ and put it before the letters?
입력 :
Input will consist of a number of lines, each containing up to 250 characters. Words will be separated by single spaces, i.e. not by tabs, double spaces or other characters. Words may be of any length. Input will be terminated by a line containing a single #.
출력 :
Output will consist of one line for each line of input. In the output line, each word (as defined in paragraph 2 above) in the input line will be reversed.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 128MB
입출력 예 :
입력 | 출력 |
teG ydaer rof eht weN dnalaeZ gnimmargorP tsetnoC no .ht41 I like ice-cream. # |
Get ready for the New Zealand Programming Contest on 14th. I ekil .maerc-eci |
풀이 :
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()
if (input == "#") break
val newStr = input
.split(" ")
.joinToString(" ") { it.reversed() }
bw.appendLine("${newStr}")
}
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
22950번: 이진수 나눗셈 (0) | 2024.08.27 |
---|---|
16944번: 강력한 비밀번호 (0) | 2024.08.27 |
31562번: 전주 듣고 노래 맞히기 (4) | 2024.08.26 |
30822번: UOSPC 세기 (0) | 2024.08.26 |
13264번: 접미사 배열 2 (0) | 2024.08.23 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!