• 문제 링크
17614번: 369
민수는 같은 반 친구들과 369게임을 하고 있다. 369게임은 여러 명이 원형으로 둘러 앉아 시작 위치의 사람이 1을 외치며 시작된다. 이후 시계방향으로 돌아가며 2, 3, 4와 같이 1씩 증가된 수가 자
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));
int n = read(), cnt = 0;
for (int i = 1; i <= n; i++) cnt += contains(i);
bw.write(String.valueOf(cnt));
bw.flush();
}
private static int contains(int i) {
int mod, cnt = 0;
do if ((mod = i % 10) == 3 || mod == 6 || mod == 9) cnt++; while ((i /= 10) > 0);
return cnt;
}
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' 카테고리의 다른 글
[백준] 17599 Bags - Data Structure / Java (0) | 2024.03.29 |
---|---|
[백준] 1837 암호제작 - Brute Force / Java (0) | 2024.03.28 |
[백준] 2501 약수 구하기 - Brute Force / Java (0) | 2024.03.26 |
[백준] 5618 공약수 - Brute Force / Java (0) | 2024.03.25 |
[백준] 10643 FUNGHI - Brute Force / Java (0) | 2024.03.24 |
댓글