Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class HuxleyCode {
- public static void main(String args[]) {
- Scanner in = new Scanner (System.in);
- boolean[][] array = new boolean[8][8];
- while(true){
- int x0,y0,x1,y1;
- x0 = in.nextInt();
- y0 = in.nextInt();
- x1 = in.nextInt();
- y1 = in.nextInt();
- if(x1 == 0 && x1 == y1 && x1 == y0 && x1 == x0){ // There are no more inputs //
- break;
- }
- x0 -= 1; y0 -= 1; x1 -= 1; y1 -= 1; // Fixing the index to fit in the array format //
- for (int i = 0;i<8;i++){ // Reseting all positions to false //
- for (int j = 0;j<8;j++){
- array[i][j] = false;
- }
- }
- if(x0 == x1 && y0 == y1){
- System.out.println(0);
- }
- else{
- array[x0][y0] = true;
- for (int i = 0; i<8; i++){
- array[i][y0] = true;
- }
- for (int i = 0;i<8; i++){
- array[x0][i] = true;
- }
- for(int i = 1;x0+i < 8 && y0+i < 8;i++){
- array[x0+i][y0+i] = true;
- }
- for(int i = 1;x0-i >= 0 && y0-i >=0;i++){
- array[x0-i][y0-i] = true;
- }
- for(int i = 1; x0+i<8 && y0-i>=0;i++){
- array[x0 + i][y0 - i] = true;
- }
- for(int i = 1; x0-i>=0 && y0+i<8;i++){
- array[x0 - i][y0 + i] = true;
- }
- if(array[x1][y1]){
- System.out.println(1);
- }
- else{
- System.out.println(2);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement