11494 - Queen
Posted: Thu Sep 25, 2008 2:23 am
Oops.. Sorry..kangroo wrote:hi everybody,
is the test case provided by "helloneo" 1 0 2 0 a valid one ??
in the problem desc its given tat 1 <= X1,Y1,X2,Y2 <= 8...
but here Y1 = 0 and Y2 = 0...
how is it posible ???
pls anyone help me to understand that test case...
Code: Select all
#include<stdio.h>
int absolute(int x)
{
if(x<0) return x*(-1);
else return x;
}
int main()
{
int x1,y1,x2,y2,move;
while(1)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if((x1==0) && (y1==0) && (x2==0) && (y2==0)) break;
if((x1==x2) && (y1==y2)) move=0;
else if((x1==x2) && (y1=!y2)) move =1;
else if((x1!=x2) && (y1==y2)) move=1;
else if((x1!=x2) && (y1!=y2))
{
if(absolute(x1-x2)==absolute(y1-y2)) move=1;
else move=2;
}
printf("%d\n",move);
}
return 0;
}
Code: Select all
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
int x1 = input.nextInt();
int y1 = input.nextInt();
int x2 = input.nextInt();
int y2 = input.nextInt();
if (x1 > 8 || x1 < 0 || x2 > 8 || x2 < 0 || y1 > 8 || y1 < 0
|| y2 > 8 || y2 < 0) {
System.exit(0);
} else if (x1 == 0 && x2 == 0 && y1 == 0 && y2 == 0) {
System.exit(0);
} else if ((Math.abs(x1 - x2) == Math.abs(y1 - y2))
|| ((x1 - x2) == 0) || ((y1 - y2) == 0)) {
System.out.println(1);
} else if ((x1 == x2) && (y1 == y2)) {
System.out.println(0);
} else {
System.out.println(2);
}
}
}
}
Code: Select all
1 8 8 8
1 5 6 1
3 7 2 8
5 5 8 8
8 3 8 3
8 3 6 1
1 3 3 1
7 8 7 1
0 0 0 0
Code: Select all
1
2
1
1
0
1
1
1