코딩테스트/SW Expert
[SWEA] 1926. 간단한 369게임
jhk828
2021. 1. 29. 22:02
1926. 간단한 369게임
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
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에서도 박수를 안치게 된다. 따라서 || 연산자로 처리한다.