본문 바로가기
(문제풀이)

백준 3052(Java) : 나머지

by cogito-new 2023. 11. 23.
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class Main_3052 {
    public static void main(String[] args) {
        Scanner scanner =  new Scanner(System.in);
        int[] array = new int[10];
       // int[] answer= new int[10];
        for(int i = 0; i < 10; i++){
          array[i] = scanner.nextInt();
          array[i] = array[i] % 42;
        };
        int count = 0;
        // 중복 제거 -> hash 사용
        HashSet<Integer> hashSet = new HashSet<>();
        for(int j = 0; j<10; j++){
            hashSet.add(array[j]);
        };
        System.out.println(hashSet.size());

    };
};

 
같은 값 확인시 이중 for문으로도 해결 가능하지만 자료구조 사용하여 풀이.

반응형