본문 바로가기
알고리즘 & 자료구조/백준

백준 3052

by 신재권 2021. 7. 7.
import java.util.Scanner;


public class Main3052 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int[] num = new int[10];
		int[] result = new int[42];
		int cnt =0;
		for(int i=0; i<num.length;i++){
			num[i] = s.nextInt();
			result[num[i]%42]++;
		}
		for(int i=0; i<result.length; i++){
			if(result[i] != 0){
				cnt++;
			}
		}
		System.out.println(cnt);

	}

}

42로 나누기때문에 나머지는 총 0~41까지의 나머지를 가지고 있다. 42길이의 배열을 선언해 , 나머지값에 따라 각 나머지에 해당하는 인덱스를 하나씩 증가시켯다.

 

마지막 for문에서 result[i]값이 0이 아니라는 것은 즉 나머지가 존재한다는 것이다. cnt++를 하면, 서로 다른 나머지의 개수를 알 수 있다. 

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 1546  (0) 2021.07.08
백준 8958  (0) 2021.07.08
백준 2577  (0) 2021.07.07
백준 2562  (0) 2021.07.07
백준 10818  (0) 2021.07.07