判断位置是否相反
java代码
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] cow = new int[11];
Arrays.fill(cow,-1);//初始牛没出现,赋值为-1
int cnt = 0;
while(n-->0){
int i = s.nextInt();
int x = s.nextInt();
if(cow[i]==-1)cow[i]=x;
else if(cow[i]==(x^1)){//位置相反说明过马路了
cnt++;cow[i]=x;
}
}
System.out.println(cnt);
}
}