PS/Java
[SWEA] 5431. 민석이의 과제 체크하기
siyamaki
2021. 3. 9. 18:01
수강생들은 1번에서 N번까지 번호가 매겨져 있고, 어떤 번호의 사람이 제출했는지에 대한 목록을 받은 것이다.
과제를 제출하지 않은 사람의 번호를 오름차순으로 출력한다.
import java.util.ArrayList;
import java.util.Scanner;
public class swea민석이의과제 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for(int tc = 1; tc <= T; tc++) {
int n = scanner.nextInt(); // 수강생 수
int k = scanner.nextInt(); // 과제 낸 사람 수
ArrayList<Integer> arr = new ArrayList<>();
for(int i = 1; i <= n; i++) {
arr.add(i);
}
//과제를 제출한 사람의 번호 K개가 주어짐
for(int i = 0; i < k; i++) {
int num = scanner.nextInt();
arr.remove((Object) num);
}
System.out.print("#" + tc + " ");
for(int i : arr) {
System.out.print(i + " ");
}
System.out.println();
}
}
}
ArrayList를 사용하였다. remove함수는 index로도 접근이 가능하지만 (Object)로 타입캐스팅을 하면 값으로도 제거가 가능하다.