CSU CHESS

 

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <string.h>
 4 
 5 int i,j,n,a,b,c,d,temp1,temp2,temp3,temp4,temp5,temp6;
 6 char a1,c1;
 7 
 8 void solve()
 9 {
10     temp1=a+b;
11     temp2=c+d;
12     temp3=a-b;
13     temp4=c-d;
14     temp5=(a+b)%2;
15     temp6=(c+d)%2;
16     if(temp5!=temp6)
17         printf("Impossible\n");
18 
19     else if(a==c&&b==d)
20         printf("0 %c %d\n",a1,b);
21     else if(temp1==temp2||temp3==temp4)
22         printf("1 %c %d %c %d\n",a1,b,c1,d);
23     else
24     {
25         int x,y;
26         x=a+b;
27         y=c-d;
28         for(int i=1; i<=8; i++)
29             if((i+i-y)==x&&(i-y)>=1&&(i-y)<=8)
30             {
31                 char temp;
32                 temp='A'+8-i;
33                 printf("2 %c %d %c %d %c %d\n",a1,b,temp,i-y,c1,d);
34                 return ;
35             }
36         x=c+d;
37         y=a-b;
38         for(int i=1; i<=8; i++)
39             if((i+i-y)==x&&(i-y)>=1&&(i-y)<=8)
40             {
41                 char temp;
42                 temp='A'+8-i;
43                 printf("2 %c %d %c %d %c %d\n",a1,b,temp,i-y,c1,d);
44                 return ;
45             }
46     }
47 }
48 int main()
49 {
50 
51     scanf("%d",&n);
52     while(n--)
53     {
54         getchar();
55         scanf("%c",&a1);
56         scanf("%d",&b);
57         getchar();
58         scanf("%c",&c1);
59         scanf("%d",&d);
60 
61 
62 
63 
64 
65         a=8-(a1-'A');
66         c=8-(c1-'A');
67 
68 
69         //printf("ans   %d %d %d %d\n",a,b,c,d);
70         solve();
71     }
72     return 0;
73 }

 

posted @ 2014-05-26 14:22  galaxy77  阅读(183)  评论(0编辑  收藏  举报