• 문제 링크
https://www.acmicpc.net/problem/27494
• 풀이 코드
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));
int n = read(), cnt = 0;
while (n > 2022) if (isValid(n--)) cnt++;
bw.write(String.valueOf(cnt));
bw.flush();
}
private static boolean isValid(int n) {
int i = 0;
do if (match(i, n % 10)) if (++i == 4) return true; while ((n /= 10) > 0);
return false;
}
private static boolean match(int i, int j) {
return (i == 0 && j == 3) || ((i == 1 || i == 3) && j == 2) || (i == 2 && j == 0);
}
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' 카테고리의 다른 글
| [백준] 12788 제 2회 IUPC는 잘 개최될 수 있을까? - Greedy / Java (0) | 2025.10.24 |
|---|---|
| [백준] 24807 Math Homework - Brute Force / Java (0) | 2025.10.22 |
| [백준] 16439 치킨치킨치킨 - Brute Force / Java (0) | 2025.10.20 |
| [백준] 32401 ANA는 회문이야 - Brute Force / Java (0) | 2025.10.19 |
| [백준] 5883 아이폰 9S - Brute Force / Java (0) | 2025.10.18 |
댓글