POJ 2996 Help Me with the Game

又是大模拟,注意黑白的迭代顺序不大一样,和poj2993相反的题目(2993不做了😂,单纯就是在各种操作字符串)

C++ Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#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;
}