https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2489
當x1=x2以及y1=y2時代表相同的點輸出0不需移動 當x2-x1=y2-y1 絕對值一樣時或x2-x1=0或y2-y1=0時輸出1 其餘輸出2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn=new Scanner(System.in);
while(scn.hasNext()){
int x1=scn.nextInt(),y1=scn.nextInt(),x2=scn.nextInt(),y2=scn.nextInt(),a=Math.abs(x1-x2),b=Math.abs(y1-y2);
if(x1==0&&y1==0&&x2==0&&y2==0)
break;
else if(x1==x2&&y1==y2)
System.out.println("0");
else if(a==b||a==0||b==0)
System.out.println("1");
else
System.out.println("2");
}
}
/*
題目:Q11494: Queen
作者:1010
時間:西元 2016 年 9 月 */
}