POJ 2996 Help Me with the Game Posted on 2023年2月22日 by hackdl #include #include #include #include #include #include #include //#include #include using namespace std;#define debug(x) cout#pragma warning(disable:4996)struct pos { int tpye; int x; int y;};bool issig(char c) { if ( (c >= 'a' && c = 'A' && c return true; } return false;}bool isbig(char c) { if ( c >= 'A' && c return true; } return false;}bool issim(char c) { if ( c >= 'a' && c return true; } return false;}bool cmpw(pos a,pos b) { if (a.tpye == b.tpye) { if (a.x == b.x) { a.y } else { return a.x > b.x; } } else{ return a.tpye } return false;}bool cmpb(pos a,pos b) { if (a.tpye == b.tpye) { if (a.x == b.x) { a.y } else { return a.x } } else{ return a.tpye } return false;}int main() { //freopen("../in1.txt", "r", stdin); string s; int x = -1; // 0 1 2 3 4 5 P //(“K”)、皇后(“Q”)、车(“R”)、主教(“B”)、骑士(“N”) map mp; mp['K'] = 0;mp['k'] = 0; mp['Q'] = 1;mp['q'] = 1; mp['R'] = 2; mp['r'] = 2, mp['B'] = 3, mp['b'] = 3, mp['N'] = 4, mp['n'] = 4, mp['P'] = 5, mp['p'] = 5; vector arr;// = { 'K','Q','R','B','N','P', }; arr.push_back('K'); arr.push_back('Q'); arr.push_back('R'); arr.push_back('B'); arr.push_back('N'); arr.push_back('P'); vector w; vector b; while (getline(cin, s)) { if (s[0] == '+') { ++x; } else if (s[0] == '|') { int y = -1; for (size_t i = 0; i if (s[i] == '|') { ++y; } else if (issig(s[i])) { if (isbig(s[i])) { pos p;// = { mp[s[i]],x,y }; p.tpye = mp[s[i]]; p.x = x; p.y = y; w.push_back(p); } else if (issim(s[i])) { pos p;// = { mp[s[i]],x,y }; p.tpye = mp[s[i]]; p.x = x; p.y = y; b.push_back(p); } } } } } sort(w.begin(), w.end(), cmpw); sort(b.begin(), b.end(), cmpb); /*White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6 */ cout for (size_t i = 0;i pos t = w[i]; if(arr[t.tpye]!='P') cout char c = (char)t.y + 'a'; cout cout if(i+1 cout } cout cout for (size_t i = 0; i pos t = b[i]; if (arr[t.tpye] != 'P') cout char c = (char)t.y + 'a'; cout cout if (i + 1 cout } cout return 0;}