Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) throws IOException {
  6. Scanner scanner = new Scanner(System.in);
  7. int n = Integer.parseInt(scanner.nextLine());
  8.  
  9. for (int i = 0; i < n; i++) {
  10. String input = scanner.nextLine();
  11. System.out.println(getValidPositions(input));
  12. }
  13. }
  14.  
  15. private static int getValidPositions(String input) {
  16. int result = 0;
  17.  
  18. int x = (input.charAt(0)) - 96;
  19. int y = Integer.parseInt(input.split("")[1]);
  20.  
  21. if(x-2 >= 1 && y-1 >=1){
  22. result ++;
  23. }
  24. if(x-2 >= 1 && y+1 <= 8) {
  25. result++;
  26. }
  27. if(x-1 >= 1 && y+2 <= 8) {
  28. result++;
  29. }
  30.  
  31. if(x+1 <= 8 && y+2 <= 8) {
  32. result++;
  33. }
  34. if(x+2<= 8 && y+1 <= 8) {
  35. result++;
  36. }
  37. if(x+2 <= 8 && y-1 >= 1) {
  38. result++;
  39. }
  40. if(x+1 <= 8 && y -2 >= 1) {
  41. result++;
  42. }
  43. if(x-1 >=1 && y-2 >= 1) {
  44. result++;
  45. }
  46.  
  47. return result;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement