๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[SW Expert Academy] - (D3)5431. ๋ฏผ์„์ด์˜ ๊ณผ์ œ ์ฒดํฌํ•˜๊ธฐ

by ์ฃผ๋ฐœ2 2020. 6. 6.
๋ฐ˜์‘ํ˜•

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

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

์ฝ”๋“œ

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		int T = Integer.parseInt(bf.readLine());
		for(int tc=1; tc<=T; tc++) {
			st = new StringTokenizer(bf.readLine());
			int N = Integer.parseInt(st.nextToken());	// ์ˆ˜๊ฐ•์ƒ ์ˆ˜
			int K = Integer.parseInt(st.nextToken());	// ๊ณผ์ œ ์ œ์ถœํ•œ ์‚ฌ๋žŒ์ˆ˜
			
			boolean[] students = new boolean[N];	// ์ˆ˜๊ฐ•์ƒ ์ˆ˜
			st = new StringTokenizer(bf.readLine());
			
			/*
			 * passHoemWork = ๊ณผ์ œ ์ œ์ถœํ•œ ์‚ฌ๋žŒ์˜ ๋ฒˆํ˜ธ.
			 * ํ•ด๋‹น ๋ฒˆํ˜ธ์˜ -1(๋ฐฐ์—ด์€ 0๋ถ€ํ„ฐ ์‹œ์ž‘)์„ true๋กœ ์„ค์ •ํ•œ๋‹ค.
			 * e.g) ๊ณผ์ œ ์ œ์ถœํ•œ ์‚ฌ๋žŒ์€ true. 
			 */
			for(int i=0; i<K; i++) {
				int passHomeWork = Integer.parseInt(st.nextToken());
				students[passHomeWork-1] = true;	
			}
			
			System.out.print("#" + tc + " ");
			for(int i=0; i<students.length; i++) {
				if(!students[i]) {
					System.out.print((i+1) + " ");
				}
			}
			System.out.println();
		}
		
		bf.close();
	}

}

ํ’€์ด

booleanํ˜•์œผ๋กœ ํ•™์ƒ ์ˆ˜๋งŒํผ ๋ฐฐ์—ด์„ ์„ ์–ธํ•˜๋ฉด ์ดˆ๊ธฐ๊ฐ’์€ false๊ฐ€ ๋œ๋‹ค.

๊ทธ ํ›„ ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๊ฐ’์œผ๋กœ, ๊ณผ์ œ๋ฅผ ์ œ์ถœํ•œ ์‚ฌ๋žŒ์˜ ๋ฒˆํ˜ธ -1 (๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘)์˜ ๊ฐ’๋“ค์„ true๋กœ ์„ค์ •ํ•ด์ฃผ๊ณ ,

์ถœ๋ ฅํ• ๋•Œ false์ธ ๊ฐ’์„ ์ถœ๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€