언어, 알고리즘 공부/백준

[백준 알고리즘] 3052번 나머지 (Python, Java)

쿠몬e 2020. 3. 2. 11:27

 

<Python>

a = []
for i in range(10):
    num = int(input())
    a.append(num%42) # 나머지를 리스트에 넣음

a = list(set(a)) # 중복제거
print(len(a))

 

<Java>

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        HashSet<Integer> h = new HashSet<Integer>();

        for(int i=0; i<10; i++)
            h.add(Integer.parseInt(br.readLine())%42);
        System.out.println(h.size());

    }
}

 

▼링크

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

반응형