자바/백준 알고리즘(자바)

[백준/자바]3052번: 나눗셈

Heeyeon Choi 2021. 11. 9. 15:32
728x90

-Set은 중복된 값을 가지지 않는 Collection

-배열을 Set 타입(HashSet)으로 변환하면, 중복을 제거할 수 있음

-배열의 순서를 보장하면서, 중복을 제거해야 할 때는 LinkedHashSet을 사용


728x90
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

import javax.print.DocFlavor.STRING;


 
public class Main {
	
	public static void main(String args[]) throws NumberFormatException, IOException{
		
		Scanner scan = new Scanner(System.in);
		int a[] = new int[10];
		int count=0;
		
		for(int i=0; i<10; i++) {
			a[i]= scan.nextInt();
			a[i] %= 42;
			
		}
		
		// 배열을 HashSet으로 변환
		HashSet<Integer> hs = new HashSet<Integer>();
		for(int num: a) {
			hs.add(num);
		}

		System.out.print(hs.size());

		
	
		
		
	}			
	
}
728x90