POJ 2996 Help Me with the Game(模拟)
注意优先级问题,样例看清楚,过了样例应该就能看出优先级不一样了。
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 using namespace std; 5 char str[13] = "KQRBNP"; 6 int main() 7 { 8 char p[101][101]; 9 int i,j,k,z; 10 for(i = 0;i <= 16;i ++) 11 { 12 gets(p[i]); 13 } 14 printf("White: "); 15 z = 1; 16 for(i = 0;i <= 5;i ++) 17 { 18 for(j = 16;j >= 1;j --)//优先级问题,和下面不一样。 19 { 20 for(k = 1;k <= 32;k ++) 21 { 22 if(p[j][k] == str[i]) 23 { 24 if(z) 25 { 26 if(i != 5) 27 printf("%c%c%d",str[i],k/4+'a',8-j/2); 28 else 29 printf("%c%d",k/4+'a',8-j/2); 30 z = 0; 31 } 32 else 33 { 34 if(i != 5) 35 printf(",%c%c%d",str[i],k/4+'a',8-j/2); 36 else 37 printf(",%c%d",k/4+'a',8-j/2); 38 } 39 } 40 } 41 } 42 } 43 printf("\n"); 44 printf("Black: "); 45 z = 1; 46 for(i = 0;i <= 5;i ++) 47 { 48 for(j = 1;j <= 16;j ++) 49 { 50 for(k = 1;k <= 32;k ++) 51 { 52 if(p[j][k] == str[i]+'a'-'A') 53 { 54 if(z) 55 { 56 if(i != 5) 57 printf("%c%c%d",str[i],k/4+'a',8-j/2); 58 else 59 printf("%c%d",k/4+'a',8-j/2); 60 z = 0; 61 } 62 else 63 { 64 if(i != 5) 65 printf(",%c%c%d",str[i],k/4+'a',8-j/2); 66 else 67 printf(",%c%d",k/4+'a',8-j/2); 68 } 69 } 70 } 71 } 72 } 73 printf("\n"); 74 return 0; 75 }