Advertisement
Guest User

Untitled

a guest
May 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool in_border ( int x, int y )
  6. {
  7.     return x >= 0 && x < 8 && y >= 0 && y < 8;
  8. }
  9.  
  10. int main() {
  11.  
  12.     int n;
  13.     cin >> n;
  14.     int dx[8] = {1,1,-1,-1,2,2,-2,-2};
  15.     int dy[8] = {2,-2,2,-2,1,-1,1,-1};
  16.     while ( n-- )
  17.     {
  18.         char a, b;
  19.         cin >> a >> b;
  20.         a -= 'a';
  21.         b -= '0' + 1;
  22.         int count_of_moves = 0;
  23.         for ( int i = 0 ; i < 8 ; i++ )
  24.            count_of_moves += in_border(a + dx [ i ], b + dy [ i ]);
  25.         cout << count_of_moves << endl;
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement