POJ 2996 Help Me with the Game Posted on 2018-09-19 | In ACM | 阅读 又是大模拟,注意黑白的迭代顺序不大一样,和poj2993相反的题目(2993不做了😂,单纯就是在各种操作字符串) C++ Code 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <vector>using namespace std;int main(){ vector<string> white[6]; vector<string> black[6]; char tmp[100]; char board[8][8]; memset(board, 0, sizeof(board)); for(int i = 7; i >= 0; i--){ scanf("%s", tmp); scanf("%s", tmp); for(int j = 0; j < 8; j++){ board[i][j] = tmp[2+j*4]; } } scanf("%s", tmp); for(int i = 0; i < 8; i++){ for(int j = 0; j < 8; j++){ if(board[i][j] == 'K'){ string pushStr = "Ka1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; white[0].push_back(pushStr); }else if(board[i][j] == 'Q'){ string pushStr = "Qa1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; white[1].push_back(pushStr); }else if(board[i][j] == 'R'){ string pushStr = "Ra1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; white[2].push_back(pushStr); }else if(board[i][j] == 'B'){ string pushStr = "Ba1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; white[3].push_back(pushStr); }else if(board[i][j] == 'N'){ string pushStr = "Na1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; white[4].push_back(pushStr); }else if(board[i][j] == 'P'){ string pushStr = "a1"; pushStr[0] = 'a' + j; pushStr[1] = '1' + i; white[5].push_back(pushStr); } } } for(int i = 7; i >= 0; i--){ for(int j = 0; j < 8; j++){ if(board[i][j] == 'k'){ string pushStr = "Ka1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; black[0].push_back(pushStr); }else if(board[i][j] == 'q'){ string pushStr = "Qa1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; black[1].push_back(pushStr); }else if(board[i][j] == 'r'){ string pushStr = "Ra1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; black[2].push_back(pushStr); }else if(board[i][j] == 'b'){ string pushStr = "Ba1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; black[3].push_back(pushStr); }else if(board[i][j] == 'n'){ string pushStr = "Na1"; pushStr[1] = 'a' + j; pushStr[2] = '1' + i; black[4].push_back(pushStr); }else if(board[i][j] == 'p'){ string pushStr = "a1"; pushStr[0] = 'a' + j; pushStr[1] = '1' + i; black[5].push_back(pushStr); } } } bool flag = false; printf("White:"); for(int i = 0; i < 6; i++){ for(int j = 0; j < white[i].size(); j++){ if(flag == false){ printf(" "); flag = true; } else printf(","); cout << white[i][j]; } } flag = false; printf("\nBlack:"); for(int i = 0; i < 6; i++){ for(int j = 0; j < black[i].size(); j++){ if(flag == false){ printf(" "); flag = true; } else printf(","); cout << black[i][j]; } } printf("\n"); return 0;}