λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Algorithm

[SW Expert Academy] - (D3)3809. ν™”μ„­μ΄μ˜ μ •μˆ˜ λ‚˜μ—΄

by 주발2 2020. 6. 15.
λ°˜μ‘ν˜•

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWHz7xD6A20DFAVB&categoryId=AWHz7xD6A20DFAVB&categoryType=CODE

 

SW Expert Academy

SW ν”„λ‘œκ·Έλž˜λ° μ—­λŸ‰ 강화에 도움이 λ˜λŠ” λ‹€μ–‘ν•œ ν•™μŠ΅ 컨텐츠λ₯Ό ν™•μΈν•˜μ„Έμš”!

swexpertacademy.com

μ½”λ“œ

import java.util.Scanner;

public class Solution {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int t = scan.nextInt();
		for(int tc=1; tc<=t; tc++) {
			int N = scan.nextInt();
			String str = "";
			
			// μž…λ ₯받은 숫자λ₯Ό λ¬Έμžμ—΄λ‘œ λΆ™μ—¬μ„œ λ§Œλ“€κΈ°.
			for(int i=0; i<N; i++) {
				str += Integer.toString(scan.nextInt());
			}
			
			// i의 값을 String으둜 λ³€ν™˜ν›„, μœ„μ—μ„œ 이어뢙인 str에 ν¬ν•¨λ˜μ§€ μ•Šμ„κ²½μš° -> κ°€μž₯ μž‘μ€ μ •μˆ˜
			for(int i=0; ; i++) {
				if(!str.contains(Integer.toString(i))) {
					System.out.println("#" + tc + " " + i);
					break;
				}
			}
		}
		scan.close();
	}

}

풀이

λ¬Έμ œμ—μ„œ 3 0 1이 주어지면, λ§Œλ“€ 수 μžˆλŠ” λͺ¨λ“  μˆ˜κ°€ μ•„λ‹ˆλΌ μ—°λ‹¬μ•„μ„œ μ˜€λŠ” 수만 λ§Œλ“€ 수 μžˆλ‹€.

3 0 1 -> 3, 0, 1, 30, 301 둜 5개λ₯Ό λ§Œλ“€ 수 μžˆλ‹€.

 

λ”°λΌμ„œ μž…λ ₯받은 λͺ¨λ“  숫자λ₯Ό λ¬Έμžμ—΄ ν˜•νƒœλ‘œ 이어뢙인닀. 3 0 1 -> "301"

 

κ·Έ ν›„ 0λΆ€ν„° μ‹œμž‘ν•΄μ„œ λ¬Έμžμ—΄μ— ν¬ν•¨λ˜μ§€ μ•ŠλŠ” μˆ˜λŠ” 주어진 수둜 λ§Œλ“€μˆ˜ μ—†λŠ” κ°€μž₯ μž‘μ€ μˆ˜λ‹€.

 

 

λ°˜μ‘ν˜•

λŒ“κΈ€