http://poj.org/problem?id=2996
1 #include<stdio.h> 2 #include<string.h> 3 char map[55][55]; 4 void find1(char ch) 5 { 6 int flag = 0; 7 for (int i = 15; i >= 1; i -= 2) 8 { 9 if (flag) 10 break; 11 for (int j = 2; j <= 30; j += 4) 12 { 13 if (map[i][j]==ch) 14 { 15 if (ch=='K') 16 { 17 printf("%c",ch); 18 flag = 1; 19 printf("%c%d",'a'+j/4,8-i/2); 20 break; 21 } 22 else if (ch=='P') 23 printf(","); 24 else 25 printf(",%c",ch); 26 printf("%c%d",'a'+j/4,8-i/2); 27 28 } 29 } 30 } 31 } 32 void find2(char ch) 33 { 34 int flag = 0; 35 for (int i = 1; i <= 15; i += 2) 36 { 37 if (flag) 38 break; 39 for (int j = 2; j <= 30; j += 4) 40 { 41 if (map[i][j]==ch) 42 { 43 if (ch=='k') 44 { 45 46 printf("%c",ch-32); 47 printf("%c%d",'a'+j/4,8-i/2); 48 flag = 1; 49 break; 50 } 51 else if(ch=='p') 52 printf(","); 53 else 54 printf(",%c",ch-32); 55 printf("%c%d",'a'+j/4,8-i/2); 56 57 } 58 } 59 } 60 } 61 int main() 62 { 63 for (int i = 0; i < 17; i ++) 64 { 65 scanf("%s",map[i]); 66 } 67 printf("White: "); 68 find1('K'); 69 find1('Q'); 70 find1('R'); 71 find1('B'); 72 find1('N'); 73 find1('P'); 74 puts(""); 75 printf("Black: "); 76 find2('k'); 77 find2('q'); 78 find2('r'); 79 find2('b'); 80 find2('n'); 81 find2('p'); 82 puts(""); 83 return 0; 84 }