Advertisement
juanjo12x

UVA_255_Correct_Move

Jul 25th, 2014
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9. int i,j,f,t,n,tt,x,y,top2,k,q,m,r,c;
  10. char map[8][8];
  11. while(scanf("%d %d %d",&k,&q,&m)==3)
  12. {
  13.                 if(k==q){
  14.                         printf("Illegal state\n");
  15.                         continue;
  16.                         }
  17.     for(i=0;i<8;i++)
  18.         for(j=0;j<8;j++)
  19.             map[i][j]='e';
  20.     r=k/8;
  21.     c=k-r*8;
  22.     map[r][c]='k';
  23.     if(r+1<8)
  24.         map[r+1][c]='o';
  25.     if(r-1>=0)
  26.         map[r-1][c]='o';
  27.     if(c+1<8)
  28.         map[r][c+1]='o';
  29.     if(c-1>=0)
  30.         map[r][c-1]='o';
  31.    
  32.     r=q/8;
  33.     c=q-r*8;
  34.     map[r][c]='q';
  35.     for(i=r;i<8&&map[i][c]!='k';i++)
  36.     {
  37.                                    
  38.         if(map[i][c]=='o')
  39.             map[i][c]='g';
  40.         else
  41.             map[i][c]='x';
  42.     }
  43.     for(i=r;i>=0&&map[i][c]!='k';i--)
  44.     {
  45.         if(map[i][c]=='o')
  46.             map[i][c]='g';
  47.         else
  48.             map[i][c]='x';
  49.     }
  50.     for(i=c;i<8&&map[r][i]!='k';i++)
  51.     {
  52.         if(map[r][i]=='o')
  53.             map[r][i]='g';
  54.         else
  55.             map[r][i]='x';
  56.     }
  57.     for(i=c;i>=0&&map[r][i]!='k';i--)
  58.     {
  59.         if(map[r][i]=='o')
  60.             map[r][i]='g';
  61.         else
  62.             map[r][i]='x';
  63.     }
  64.         r=q/8;
  65.     c=q-r*8;
  66.     map[r][c]='q';
  67.     y=m/8;
  68.     x=m-y*8;
  69.     if(map[y][x]=='g')
  70.         printf("Move not allowed\n");
  71.     else if(map[y][x]!='x')
  72.         printf("Illegal move\n");
  73.     else if(map[y][x]=='x')
  74.     {
  75.          if(m==49&&k==56||m==14&&k==7||m==9&&k==0||m==54&&k==63)
  76.              printf("Stop\n");
  77.          else
  78.              printf("Continue\n");
  79.      }
  80.        
  81. }
  82.  
  83.    
  84.     return  0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement