#include #include #include #include using namespace std; struct pawn { char fig, col, row; }; int getfig(char f) { switch(f) { case 'K': return 0; case 'Q': return 1; case 'R': return 2; case 'B': return 3; case 'N': return 4; } return 5; } bool cmp_pawn_white (pawn a, pawn b) { int ia, ib; // a < b == true ia = getfig(a.fig); ib = getfig(b.fig); if (ia!=ib) return (ia < ib); if (a.row!=b.row) return (a.row < b.row); return (a.col < b.col); } bool cmp_pawn_black (pawn a, pawn b) { int ia, ib; // a < b == true ia = getfig(a.fig); ib = getfig(b.fig); if (ia!=ib) return (ia < ib); if (a.row!=b.row) return (a.row > b.row); return (a.col < b.col); } int main() { char tmp[40]; vector white, black; int i, j; for (i=0; i < 8; i++) { gets(tmp); // dummy line gets(tmp); for (j=0; j<8; j++) { pawn p; bool iswhite; p.fig = tmp[2+j*4]; if ((p.fig != '.') && (p.fig != ':')) { iswhite = (p.fig == toupper(p.fig)); p.fig = toupper(p.fig); p.col = 'a' + j; p.row = '0' + (8-i); if (iswhite) white.push_back(p); else black.push_back(p); } } } sort(white.begin(), white.end(), cmp_pawn_white); sort(black.begin(), black.end(), cmp_pawn_black); vector::iterator ii; bool first = true; printf ("White: "); for (ii = white.begin(); ii != white.end(); ii++) { if (first) { first = false; } else { printf(","); } if (ii->fig != 'P') printf("%c", ii->fig); printf("%c%c", ii->col, ii->row); } printf ("\n"); first = true; printf ("Black: "); for (ii = black.begin(); ii != black.end(); ii++) { if (first) { first = false; } else { printf(","); } if (ii->fig != 'P') printf("%c", ii->fig); printf("%c%c", ii->col, ii->row); } printf ("\n"); return 0; }