백준 - 소가 길을 건너간 이유(14467)

정민주·2024년 1월 27일

코테

목록 보기
5/95

⭐문제 : https://www.acmicpc.net/problem/14467

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Objects;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        HashMap<String, String> cowInfo = new HashMap<String, String>();
        StringTokenizer st;
        int answer = 0;

        int T = Integer.parseInt(br.readLine());
        for(int i=0; i<T; i++){
            st = new StringTokenizer(br.readLine(), " ");
            String num = st.nextToken();
            String location = st.nextToken();

            if (Objects.equals(cowInfo.get(num), null)) {
                cowInfo.put(num, location);
                continue;
            }

            String exLocation = cowInfo.get(num);
            if(!exLocation.equals(location)){
                cowInfo.put(num,location);
                answer++;
            }

        }
        System.out.println(answer);
    }
}

0개의 댓글