공부기록/백준

[백준] 13414번 수강신청

메델 2024. 1. 3. 22:39
import java.util.LinkedHashSet;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    	
    	Scanner kb = new Scanner(System.in);
    	
    	int k = kb.nextInt();
    	int L = kb.nextInt();
    	
    	LinkedHashSet<String> set = new LinkedHashSet<>();
    	
    	
    	for(int i=0; i<L; i++) {
    		
    		String number = kb.next();
    		
    		if(set.contains(number)) {
    			set.remove(number);
    		}
    		
    		set.add(number);
    	}
    	
    	for(String x: set) {
    		System.out.println(x);
    		k--;
    		
    		if(k == 0) break;
    	}

    	
    }
}