perry05

[백준] 3052- 나머지(JAVA) 본문

문제풀이 기록/JAVA

[백준] 3052- 나머지(JAVA)

perry05 2022. 11. 25. 11:14

[백준] 단계별로 풀어보기 - 1차원 배열

https://www.acmicpc.net/problem/3052

 

3052번: 나머지

각 수를 42로 나눈 나머지는 39, 40, 41, 0, 1, 2, 40, 41, 0, 1이다. 서로 다른 값은 6개가 있다.

www.acmicpc.net

 

> 문제

 

> 풀이

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = 42;
		int count = 0;
		boolean[] arr = new boolean[n];
		
		// 입력받은 후 해당 숫자에 표시하고 개수세기
		for(int i = 0; i < 10; i++) {
			int num = Integer.parseInt(br.readLine());
			num = num % n;
			if(!arr[num]) {
				arr[num] = true;
				count++;
			}
		}
		br.close();
		
		// 출력
		System.out.println(count);
	}
}
Comments