문제 출처 : https://www.acmicpc.net/problem/3578
언어 : Kotlin
문제 설명 :
You may have seen a mechanic typewriter — such devices were widespread just 15 years ago, before computers replaced them. It is a very simple thing. You strike a key on the typewriter keyboard, the corresponding type bar rises, and the metallic letter molded into the type bar strikes the paper. The art of typewriter typing, however, is more complicated than the art of computer typing. You should strike keys with some force otherwise the prints will not be dark enough. Also you should not overdo it otherwise the paper will be damaged.
Imagine a typewriter with very sharp letters, which cut the paper instead of printing. It is clear that digit 0 being typed on the typewriter makes a nice hole in the paper and you receive a small paper oval as a bonus. The same happens with some other digits: 4, 6, 9 produce one hole, and 8 produces two touching holes. The remaining digits just cut the paper without making holes.
The Jury thinks about some exhibition devoted to the oncoming jubilee of Pascal language. One of the ideas is to make an art installation, consisting of an empty sheet of paper with exactly h (0 ≤ h ≤ 510) holes made by typing a non-negative integer number on the cutting typewriter described above. The number must be minimal possible and should not have leading zeroes. Unluckily we are too busy with preparing the ACM quarter- and semifinals, so we need your help and ask you to write a computer program to generate the required number.
입력 :
A single integer number h — the number of holes.
출력 :
The integer number which should be typed.
제한 사항 :
- 시간 제한 : 3초
- 메모리 제한 : 256MB
입출력 예 :
입력 | 출력 |
0 | 1 |
1 | 0 |
15 | 48888888 |
70 | 88888888888888888888888888888888888 |
풀이 :
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))
val sb = StringBuilder()
val h = readLine().toInt()
if (h % 2 == 0) {
sb.append("8".repeat(h / 2))
if (sb.isBlank()) sb.append("1")
} else {
val quotient = h / 2
val remainder = h % 2
if (quotient > 0) {
bw.write("4${"0".repeat(remainder - 1)}${"8".repeat(quotient)}")
} else {
bw.write("0")
}
}
bw.write(sb.toString())
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
31867번: 홀짝홀짝 (0) | 2024.07.15 |
---|---|
26742번: Skarpetki (0) | 2024.07.12 |
4583번: 거울상 (0) | 2024.07.12 |
5376번: 소수를 분수로 (0) | 2024.07.11 |
8371번: Dyslexia (0) | 2024.07.11 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!