• 문제 링크
3578번: Holes
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 mo
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int h = read();
if (h == 0) sb.append("1");
else if (h == 1) sb.append("0");
else {
if ((h & 1) == 1) sb.append("4");
int i = h / 2;
while (i-- > 0) sb.append("8");
}
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 15001 Frog Leaps - Greedy / Java (0) | 2024.04.12 |
---|---|
[백준] 27106 Making Change - Greedy / Java (0) | 2024.04.11 |
[백준] 5992 The Leisurely Stroll - Graph Theory / Java (0) | 2024.04.09 |
[백준] 9790 Elephant Show - Graph Theory / Java (0) | 2024.04.08 |
[백준] 5975 Pathfinding - Graph Theory / Java (0) | 2024.04.07 |
댓글