#include #include #include #include using namespace std; int ptoi(char p) { switch(p) { case 'K': return 5; break; case 'Q': return 4; break; case 'R': return 3; break; case 'B': return 2; break; case 'N': return 1; break; default: return 0; }; } bool cmp( string a, string b, int white ) { int a1 = ptoi(a[0]); int b1 = ptoi(b[0]); if( a1 > b1 ) return true; else if( b1 > a1 ) return false; char ar, br; int ac, bc; if( a1 == 0 ) { // pawns ac = a[0]; bc = b[0]; ar = a[1]; br = b[1]; } else { ac = a[1]; bc = b[1]; ar = a[2]; br = b[2]; } // row if( white == 1 ) { if( ar > br ) return true; else return false; } else { if( ar < br ) return true; else return false; } return (ac < bc); } bool whitecmp( string a, string b ) { return cmp(a, b, 0); } bool blackcmp( string a, string b ) { return cmp(a, b, 1); } int main( int argc, char ** argv ) { vector white, black; char line[256]; for( int vrow=1; vrow < 18; vrow++ ) { cin.getline(line, 256); if( (vrow % 2) == 1 ) continue; for( int col=0; col<8; col++ ) { char piece = 0; for( int v=0; v<4; v++ ) { if( isalpha(line[col*4+v]) ) { piece = line[col*4+v]; } } if( piece == 0 ) continue; // no piece if( (piece >= 'a') && (piece <= 'z') ) { // Black string desc; if( piece != 'p' ) desc += piece - ('a' - 'A'); desc += col+'a'; desc += -((vrow/2)-9) + '0'; black.push_back(desc); } else { // White string desc; if( piece != 'P' ) desc += piece; desc += col+'a'; desc += -((vrow/2)-9) + '0'; white.push_back(desc); } } } // Sort sort(white.begin(), white.end(), whitecmp); sort(black.begin(), black.end(), blackcmp); // Output cout << "White: "; for( vector::iterator i = white.begin(); i != white.end(); i++ ) { if( i!= white.begin() ) cout << ","; cout << *i; } cout << endl; cout << "Black: "; for( vector::iterator i = black.begin(); i != black.end(); i++ ) { if( i!= black.begin() ) cout << ","; cout << *i; } cout << endl; return 0; }