• 문제 링크
https://www.acmicpc.net/problem/1284
• 풀이 코드
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 n;
while ((n = read()) != 0) sb.append(calc(n)).append("\n");
bw.write(sb.toString());
bw.flush();
}
private static int calc(int n) {
int sum = 1, i;
do sum += (i = n % 10) == 1 ? 3 : i == 0 ? 5 : 4; while ((n /= 10) > 0);
return sum;
}
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' 카테고리의 다른 글
[백준] 1408 24 - Implementation / Java (0) | 2025.01.16 |
---|---|
[백준] 10988 팰린드롬인지 확인하기 - Implementation / Java (0) | 2025.01.15 |
[백준] 1652 누울 자리를 찾아라 - Implementation / Java (0) | 2025.01.13 |
[백준] 18406 럭키 스트레이트 - Implementation / Java (0) | 2025.01.12 |
[백준] 9076 점수 집계 - Implementation / Java (0) | 2025.01.11 |
댓글