5949번: Adding Commas백준/문제2024. 7. 23. 14:28
Table of Contents
문제 출처 : https://www.acmicpc.net/problem/5949
언어 : Kotlin
문제 설명 :
Bessie is working with large numbers N (1 <= N <= 2,000,000,000) like 153920529 and realizes that the numbers would be a lot easier to read with commas inserted every three digits (as is normally done in the USA; some countries prefer to use periods every three digits). Thus, she would like to add commas: 153,920,529. Please write a program that does this.
입력 :
Line 1: A single integer: N
출력 :
Line 1: The integer N with commas inserted before each set of three digits except the first digits (as traditionally done in many cultures)
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 128MB
입출력 예 :
입력 | 출력 |
153920529 | 153,920,529 |
풀이 :
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))
bw.write(readLine().reversed().chunked(3).joinToString(",").reversed())
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
10932번: SHA-512 (0) | 2024.07.24 |
---|---|
14174번: Block Game (0) | 2024.07.24 |
26731번: Zagubiona litera (0) | 2024.07.23 |
5211번: 가단조와 다장조 (0) | 2024.07.23 |
31746번: SciComLove (2024) (0) | 2024.07.22 |
@스몰스테핑 :: 작은 발걸음
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!