티스토리 뷰

1926. 간단한 369게임

swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PTeo6AHUDFAUq&categoryId=AV5PTeo6AHUDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

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에서도 박수를 안치게 된다. 따라서 || 연산자로 처리한다.

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함