반응형

이번주는 난이도가 살짝 있던 문제들이 있어서 재밌었다.

3주차를 해보면서 그동안 느낀점은

다른 코테 연습 사이트보다 좋은점은 개념을 좀 더 정확히 알 수 있도록 비슷한 문제를 여러개 풀게 시켜준다.

조별과제가 끝나기 전까지 파이팅!

 

프로그래밍 기초부분 05 단순 반복문 - 반복문 안의 if 완료

 

문제 - 369 게임

https://www.codetree.ai/missions/4/problems/369-game/submissions

 

코드트리 | 코딩테스트 준비를 위한 알고리즘 정석

국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.

www.codetree.ai

 

코드

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0 || Include369(i)) {
                System.out.print(0 + " ");
            } else
                System.out.print(i + " ");
        }


        sc.close();
    }

    public static boolean Include369(int num) {
        boolean result = false;

        while (num != 0) {
            int digit = num % 10;
            if (digit == 3 || digit == 6 || digit == 9) {
                result = true;
                break;
            }
            num /= 10;
        }
        return result;
    }


}
반응형

+ Recent posts