백준

[백준] 14467번 소가 길을 건너간 이유 1 (java, 구현)

해랑쓰 2021. 4. 29. 17:28
728x90
반응형

www.acmicpc.net/problem/14467

 

14467번: 소가 길을 건너간 이유 1

3번 소는 위치 1, 0, 1에서 관찰되었으므로 길을 최소 두 번 건넜음을 확인할 수 있다. 4번 소도 길을 한 번 건넜으며, 나머지 소는 길을 건넌 기록이 확인되지 않는다.

www.acmicpc.net

 

import java.util.Arrays;
import java.util.Scanner;

public class B_14467_소가길을건너간이유1_Main {
	static int n;
	static int[] cow;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int answer=0;
		n=sc.nextInt();
		cow=new int[11];
		Arrays.fill(cow, -1);
		
		for (int i = 0; i < n; i++) {
			int num=sc.nextInt();
			int pos=sc.nextInt();
			if(cow[num]==-1) {
				cow[num]=pos;
			}else if(cow[num]!=pos) {
				cow[num]=pos;
				answer+=1;
			}
		}
		

		System.out.println(answer);
	}
}
728x90
반응형