|
|
back to board#wa 20 What's wrong ? Posted by spidey 16 Feb 2016 12:30 This is my code import java.util.*; public class Task_2010 { static void kingStep(int n, int x, int y){ long countKing = 0; if((x - 1) > 0) countKing++; if((x - 1) > 0 && y + 1 <= n) countKing++; if((y + 1) <= n) countKing++; if((x + 1) <= n && (y + 1) <= n) countKing++; if((x + 1) <= n) countKing++; if((x + 1) <= n && (y - 1) > 0) countKing++; if((y - 1) > 0) countKing++; if((x - 1) > 0 && (y - 1) > 0) countKing++; System.out.println("King: " + countKing); } static void knightStep(int n, int x, int y){ long countKnight = 0; if((x - 2) > 0 && (y + 1) <= n) countKnight++; if((x - 2) > 0 && (y - 1) > 0) countKnight++; if((y + 2) <= n && (x - 1) > 0) countKnight++; if((y + 2) <= n && (x + 1) <= n) countKnight++; if((x + 2) <= n && (x + 1) <= n) countKnight++; if((x + 2) <= n && (y - 1) > 0) countKnight++; if((y - 2) > 0 && (x + 1) <= n) countKnight++; if((y - 2) > 0 && (x - 1) > 0) countKnight++; System.out.println("Knight: " + countKnight); } static long bishopStep(int n, int x, int y) { long countBishop = 0; int left = x - 1; int right = n - x; if(y + left <= n){ countBishop += left; } else countBishop += n - y; if(y + right <= n){ countBishop += right; } else countBishop += n - y; if(y - left > 0){ countBishop += left; } else countBishop += y - 1; if(y - right > 0){ countBishop += right; } else countBishop += y - 1; System.out.println("Bishop: " + countBishop); return countBishop; } static long rookStep(int n, int x, int y){ long countRook = (x - 1) + (n - x) + (y - 1) + (n - y); System.out.println("Rook: " + countRook); return countRook;
} public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt();
kingStep(n,x,y); knightStep(n,x,y); long queen = (bishopStep(n,x,y) + rookStep(n,x,y)); System.out.println("Queen: " + queen);
} } Re: #wa 20 What's wrong ? опечатка в knightStep. |
|
|