Codeforces : 228A - Is your horseshoe on the other hoof?

HoJeong Im·2021년 10월 26일
0

Codeforces

목록 보기
3/13

문제

코드

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

public class A_Is_your_horsehoe_on_the_other_hoof {
	
	static BufferedReader br;
	static StringTokenizer stk;
	
	static int toInt(String msg) {
		return Integer.parseInt(msg);
	}
	
	static StringTokenizer toToken(String msg) {
		stk = new StringTokenizer(msg);
		return stk;
	}
	
	public static void main(String[] args) throws IOException{
		br = new BufferedReader(new InputStreamReader(System.in));
		Set<Integer> sets = new HashSet<>();
		stk = toToken(br.readLine());
		for(int i = 0 ; i < 4 ; i++) {
			sets.add(toInt(stk.nextToken()));
		}
		System.out.println(4-sets.size());
	}
}

회고

  • 문제 이해를 빠르게 하면 할 수록 코드를 더욱 쉽게 작성할 수 있습니다.

  • set을 이용해서 중복을 제거한 원소들의 개수를 얻어서 4에서 빼주는 결과로 풀이

profile
꾸준함이 제일 빠른 길이었다

0개의 댓글