티스토리 뷰
1926. 간단한 369게임
import java.util.Scanner;
public class SWEA1926 {
// 210129
// 1926. 간단한 369게임
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int i = 1; i <= N; i++) {
int d = 1;
if (i >= 10 && i < 100)
d = 10;
else if (i >= 100 && i < 1000)
d = 100;
else if (i == 1000)
d = 1000;
boolean flag = false;
int tmp = i;
while (d > 0) {
int num = tmp / d;
if (num == 3 || num == 6 || num == 9) {
flag = true;
System.out.print("-");
}
tmp -= num * d;
d /= 10;
} // while
if (!flag)
System.out.print(i);
System.out.print(" ");
} // for
sc.close();
} // main
}
은근 오래 걸렸다.
숫자에 3, 6, 9가 들어가 있는 숫자에서 박수를 치지 않는다. 이를 3으로 나누어 떨어질 때 박수를 친다고 처리하면 0에서도 박수를 안치게 된다. 따라서 || 연산자로 처리한다.
'코딩테스트 > SW Expert' 카테고리의 다른 글
[SWEA] 1954. 달팽이 숫자 (0) | 2021.01.30 |
---|---|
[SWEA] 2007. 패턴 마디의 길이 (0) | 2021.01.29 |
[SWEA] 1859. 백만 장자 프로젝트 (0) | 2021.01.28 |
[SWEA] 1204. [S/W 문제해결 기본] 1일차 - 최빈수 구하기 (0) | 2021.01.28 |
[SWEA] 1974. 스도쿠 검증 (0) | 2021.01.21 |
댓글