题目链接。
分析:
简单模拟。
#include <iostream> #include <queue> #include <cstdio> #include <cstring> #include <cmath> using namespace std; char White[] = "KQRBNP"; char Black[] = "kqrbnp"; char G[10][10], s[50]; int main(){ memset(G, 0, sizeof(G)); for(int i=0; i<17; i++) { scanf("%s", s); if(i % 2 == 1) { for(int j=0; s[j]; j++) { if(isalpha(s[j])) G[i/2][(j-2)/4] = s[j]; } } } bool first = true; printf("White: "); for(int k=0; k<6; k++) { for(int i=7; i>=0; i--) { for(int j=0; j<8; j++) { if(G[i][j] == White[k]) { if(first) { printf("%c%c%d", White[k], 'a'+j, 8-i); first = false; } else { if(White[k] == 'P') printf(",%c%d", 'a'+j, 8-i); else printf(",%c%c%d", White[k], 'a'+j, 8-i); } } } } } putchar(' '); first = true; printf("Black: "); for(int k=0; k<6; k++) { for(int i=0; i<8; i++) { for(int j=0; j<8; j++) { if(G[i][j] == Black[k]) { if(first) { printf("%c%c%d", Black[k]+'A'-'a', 'a'+j, 8-i); first = false; } else { if(Black[k] == 'p') printf(",%c%d", 'a'+j, 8-i); else printf(",%c%c%d", Black[k]+'A'-'a', 'a'+j, 8-i); } } } } } putchar(' '); return 0; }