https://www.acmicpc.net/problem/5597
숙제를 한 학생은 28명임으로 28번만 반복을 돌려 수를 입력받는다.
28번의 수를 각각 배열 주소로 놓고 해당 값을 1로 놓는다.
새로운 반복문에서 30까지 반복하여 0인 수를 찾는다.
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int student[] = new int [31];
for(int i = 0; i < 28; i++){
int hw = sc.nextInt();
student[hw] = 1;
}
for(int i = 1; i <= 30; i++){
if(student[i] != 1) System.out.println(i);
}
sc.close();
}
}
4.후기
처음에 student 배열에 순서대로 값을 주고 0인 수를 찾으려고 했더니 값이 나오지 않았다. student [i]가 아닌 [hw] 에 대한 생각도 해봐야겠다.