Advertisement
erfanul007

Timus 1197

Apr 14th, 2021
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<stdio.h>
  2. //resubmission
  3. int main()
  4. {
  5.     int i,n,x,y,cnt;
  6.     char c[10];
  7.     scanf("%d",&n);
  8.     for(i=0;i<n;i++){
  9.         scanf("%s",c);
  10.         x=c[0]-96;
  11.         y=c[1]-48;
  12.         cnt=0;
  13.         if(x+2<=8 && y+1<=8)
  14.             cnt++;
  15.         if(x+1<=8 && y+2<=8)
  16.             cnt++;
  17.         if(x-1>=1 && y+2<=8)
  18.             cnt++;
  19.         if(x-2>=1 && y+1<=8)
  20.             cnt++;
  21.         if(x-2>=1 && y-1>=1)
  22.             cnt++;
  23.         if(x-1>=1 && y-2>=1)
  24.             cnt++;
  25.         if(x+1<=8 && y-2>=1)
  26.             cnt++;
  27.         if(x+2<=8 && y-1>=1)
  28.             cnt++;
  29.         printf("%d\n",cnt);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement