#include #include #include #include using namespace std; struct Fig { int type; int r; int c; Fig(char ch, int _r, int _c) { r = _r; c = _c; // type ch = (char) toupper(ch); switch (ch) { case 'K': type = 1; break; case 'Q': type = 2; break; case 'R': type = 3; break; case 'B': type = 4; break; case 'N': type = 5; break; case 'P': type = 6; break; default: type = -1; } } string toString() { string res; switch (type) { case 1: res += "K"; break; case 2: res += "Q"; break; case 3: res += "R"; break; case 4: res += "B"; break; case 5: res += "N"; break; } res += 'a' + c; res += '1' + r; return res; } }; list black; list white; bool bwhite; void addFig(char ch, int r, int c) { // cout << "read fig: " << ch << r << c << endl; Fig f(ch, r, c); if (isupper(ch)) { white.push_back(f); } else { black.push_back(f); } } bool sortFig(Fig a, Fig b) { bool res = false; if (a.type != b.type) { res = a.type - b.type > 0; } else { if (bwhite) { if (a.r != b.r) { res = a.r - b.type > 0; } else { res = a.c - b.c > 0; } } else { if (a.r != b.r) { res = a.r - b.type < 0; } else { res = a.c - b.c > 0; } } } return !res; } void printResult(list l) { if (bwhite) { cout << "White: "; } else { cout << "Black: "; } list::iterator it = l.begin(); string s = (*it).toString(); cout << s; it++; for (; it != l.end(); it++) { s = (*it).toString(); cout << "," << s; } cout << endl; } int main() { string row; char ch; while ((ch = cin.get()) != EOF) { white.clear(); black.clear(); for (int r = 7; r >= 0; r--) { cin >> row; cin.get(); for (int c = 0; c < 8; c++) { cin.get(); cin.get(); ch = cin.get(); if (ch != '.' && ch != ':') { addFig(ch, r, c); } cin.get(); } cin.get(); // end of row } cin >> row; cin.get(); bwhite = true; white.sort(sortFig); printResult(white); bwhite = false; black.sort(sortFig); printResult(black); // cout << endl; } return 0; }