Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws IOException {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < n; i++) {
- String input = scanner.nextLine();
- System.out.println(getValidPositions(input));
- }
- }
- private static int getValidPositions(String input) {
- int result = 0;
- int x = (input.charAt(0)) - 96;
- int y = Integer.parseInt(input.split("")[1]);
- if(x-2 >= 1 && y-1 >=1){
- result ++;
- }
- if(x-2 >= 1 && y+1 <= 8) {
- result++;
- }
- if(x-1 >= 1 && y+2 <= 8) {
- result++;
- }
- if(x+1 <= 8 && y+2 <= 8) {
- result++;
- }
- if(x+2<= 8 && y+1 <= 8) {
- result++;
- }
- if(x+2 <= 8 && y-1 >= 1) {
- result++;
- }
- if(x+1 <= 8 && y -2 >= 1) {
- result++;
- }
- if(x-1 >=1 && y-2 >= 1) {
- result++;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement