每个用例之间有个空行,最后一个没有
Black - 1 White - 4
1 4 数字是精度2
#include <iostream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
struct Node
{
int x, y, flag;
Node() :x(0), y(0), flag(0) {}
Node(int a, int b, int c) :x(a), y(b), flag(c) {}
};
char matrix[9][9],ope = 0,order[64];
Node m[100];
int nCount = 0;
/*
7 0 1
6 2
5 4 3
*/
int dir[8][2] = { {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1} };
void FillNext(int x, int y, int xAdd, int yAdd, char op) {
x += xAdd;
y += yAdd;
while (x >= 1 && x <= 8 && y >= 1 && y <= 8 && matrix[x][y] != op) {
matrix[x][y] = op;
x += xAdd;
y += yAdd;
}
}
bool GetNext(int x, int y, int xAdd, int yAdd, char op) {
x += xAdd;
y += yAdd;
int t = 0;
while (x >= 1 && x <= 8 && y >= 1 && y <= 8 && matrix[x][y] == op) {
x += xAdd;
y += yAdd;
++t;
}
if (t && x >= 1 && x <= 8 && y >= 1 && y <= 8 && matrix[x][y] != '-') return true;
return false;
}
int GetOperator(int x, int y, char op) {
int flag = 0,nx = x - 1;
char other = op == 'W' ? 'B' : 'W';
for (int i = 0; i < 8; ++i) {
if (GetNext(x, y, dir[i][0], dir[i][1], other)) flag |= 1 << i;
}
return flag;
}
int CheckOperator(char op) {
nCount = 0;
for (int i = 1; i < 9; ++i) {
for (int j = 1; j < 9; ++j) {
if(matrix[i][j] != '-') continue;
int f = GetOperator(i, j, op);
if (f) { m[nCount++] = Node(i, j, f); }
}
}
return nCount;
}
void Moved(int x, int y, char& op) {
int flag = GetOperator(x, y, op);
if(flag == 0) op = op == 'W' ? 'B' : 'W';
flag = GetOperator(x, y, op);
matrix[x][y] = op;
for (int i = 0; i < 8; ++i) {
if (flag & (1 << i) ) {
FillNext(x, y, dir[i][0], dir[i][1], op);
}
}
}
void Print() {
for (int i = 1; i < 9; ++i) {
for (int j = 1; j < 9; ++j) {
cout << matrix[i][j];
}
cout << endl;
}
}
void PrintOpe()
{
for (int i = 0; i < nCount; ++i) {
if (i) cout << " ";
cout << "(" << m[i].x << "," << m[i].y << ")";
}
if (!nCount)cout << "No legal move.";
cout << endl;
}
void PrintCount() {
int b = 0, w = 0;
for (int i = 1; i < 9; ++i) {
for (int j = 1; j < 9; ++j) {
if (matrix[i][j] == 'W')w++;
else if (matrix[i][j] == 'B')b++;
}
}
cout << "Black - " <<setw(2)<< b << " White - " <<setw(2)<< w << endl;
}
int main()
{
int t;
cin >> t;
while (t--) {
for (int i = 1; i < 9; ++i) {
for (int j = 1; j < 9; ++j)
cin >> matrix[i][j];
}
cin >> ope;
while (cin >> order) {
if (order[0] == 'L') {
CheckOperator(ope);
PrintOpe();
}
else if (order[0] == 'M'){
int x = order[1] - '0', y = order[2] - '0';
Moved(x, y, ope);
PrintCount();
ope = ope == 'W' ? 'B' : 'W';
}
else if (order[0] == 'Q') {
Print();
break;
}
}
if (t) cout << endl;
}
return 0;
}