Perlik

Untitled

Jun 15th, 2011
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. #define y1 Y1
  5. const int dx[]={-2,-2,-1,1,2,2,1-1};
  6. const int dy[]={-1,1,2,2,1,-1,-2,-2};
  7. void get_k(char x,char y,int &xk,int &yk)
  8. {
  9.     xk=x-97;
  10.     yk=y-49;
  11. }
  12. bool lad(int xb,int yb,int xk,int yk)
  13. {
  14.     return xb==xk || yb==yk;
  15. }
  16. bool kon(int xb,int yb,int xk,int yk)
  17. {
  18.     for(int q=0;q<8;q++)
  19.         if (xb+dx[q]==xk && yb+dy[q]==yk) return true;
  20.     return false;
  21. }
  22. char xt1,yt1,xt2,yt2;
  23. int x1,y1,x2,y2;
  24. int main()
  25. {
  26.     cin>>xt1>>yt1>>xt2>>yt2;
  27.     get_k(xt1,yt1,x1,y1);
  28.     get_k(xt2,yt2,x2,y2);
  29.     //cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
  30.     if (lad(x1,y1,x2,y2) || kon(x2,y2,x1,y1))
  31.     {
  32.         cout<<0;
  33.         return 0;
  34.     }
  35.     int ans=0;
  36.     for(int i=0;i<8;i++)
  37.         for(int j=0;j<8;j++)
  38.         {
  39.             if (i==x1 && j==y1 || i==x2 && j==y2) continue;
  40.             if(!lad(x1,y1,i,j) && !kon(x2,y2,i,j) && !kon(i,j,x1,y1)) ans++;
  41.         }
  42.     cout<<ans;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment