https://www.acmicpc.net/problem/3052
배열 값을 42로 나눈 나머지를 배열 안에 저장한다.
for문을 이중으로 사용하여 배열을 i와 j를 통해 그 다음 값이 같은 지 확인한다.
그 후 배열 갯수를 더하고 출력한다.
package com.example.baekjoon;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int [10];
int cnt = 0;
for(int i = 0; i < arr.length; i++){
arr[i] = sc.nextInt() % 42;
}
for(int i = 0; i < arr.length; i++){
int temp = 0;
for (int j = i + 1; j < arr.length; j++){
if(arr[i] == arr[j]) temp++;
}
if(temp == 0) cnt++;
}
System.out.println(cnt);
sc.close();
}
}
배열의 크기 비교까지는 구현을 완료하였지만 그 다음 수와 비교를 어떻게 해야할 지 고민을 많이 하였다.
https://readme.tistory.com/19 님의 블로그를 참고하였다.