말랑한 하루

[SW Expert Academy] 1926 간단한 369게임 [Java] 본문

문제풀이/SWexpert Academy

[SW Expert Academy] 1926 간단한 369게임 [Java]

지수는말랑이 2021. 1. 21. 21:45
반응형

[ 핵심풀이 ]

[ 핵심소스 ]

[ Java ]

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        for(int t=1;t<=tc;t++) {
            int N = sc.nextInt();
            for(int i=1;i<=N;i++) {
                String temp = ""+i;
                int cnt=0;
                for(int k=0;k<temp.length();k++)
                    if (temp.charAt(k) == '3' ||
                    temp.charAt(k) == '6' ||
                    temp.charAt(k) == '9')
                        cnt++;
                if (cnt==0) System.out.print(temp+" ");
                else {
                    for(int k=0;k<cnt;k++) System.out.print("-");
                    System.out.print(" ");
                }
            }
        }
        sc.close();
    }
} 
반응형
Comments