본문 바로가기

Java/SWEA

[JAVA] SWEA 1288. 새로운 불면증 치료법

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

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

정답 

 

import java.util.*;
 
class Solution {    
     
    public static void main(String args[]) throws Exception {
         
        Scanner sc = new Scanner(System.in);
        int T = Integer.parseInt(sc.nextLine());
         
        String arr[] = {"0","1","2","3","4","5","6","7","8","9"};
         
        for (int t = 1; t <= T; t++)
        { 
            int N = sc.nextInt();
             
            Set<String> set = new HashSet<String>();
            int ans = 1;
             
            while(true)
            {
                 
                String s = String.valueOf(N*ans);
                     
                for(int i=0; i<s.length(); i++)
                {
                    set.add(String.valueOf(s.charAt(i)));
                }
                ans++;
                 
                //set과 arr이 동일하다면 break;
                if(Arrays.equals(arr,set.toArray()))
                {
                    break;
                }
            }
             
            System.out.printf("#%d %d\n",t,N*(ans-1));
        }
    }
}