Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef struct pos{
- int row;
- int col;
- pos operator = (const pos &rhs){
- row = rhs.row;
- col = rhs.col;
- }
- }pos;
- /// U UR R DR D DL L UL
- pos ctrl[8] = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
- vector<vector<int>> table(9, vector<int>(9, 0)); /// B = 1 W = 2
- void PrintTable(){
- for(int i = 1; i <= 8; ++i){
- for(int j = 1; j <= 8; ++j){
- switch(table[i][j]){
- case 0:
- cout << ".";
- break;
- case 1:
- cout << "X";
- break;
- case 2:
- cout << "O";
- break;
- }
- }
- cout << "\n";
- }
- return;
- }
- int main(){
- int r, p, row;
- char col;
- bool found;
- pos tr, c;
- table[4][5] = 1;
- table[5][4] = 1;
- table[4][4] = 2;
- table[5][5] = 2;
- scanf("%d", &r);
- for(int i = 1; i <= r; ++i){
- if(i % 2 == 0){
- p = 2;
- } else {
- p = 1;
- }
- scanf(" %c", &col);
- scanf("%d", &row);
- tr = {row, col - 'a' + 1};
- table[tr.row][tr.col] = p;
- for(int j = 0; j < 8; ++j){
- c = {tr.row + ctrl[j].row, tr.col + ctrl[j].col};
- found = false;
- while(c.row > 0 && c.row <= 8 && c.col > 0 && c.col <= 8){
- if(table[c.row][c.col] == 0){
- break;
- } else if(table[c.row][c.col] == p){
- found = true;
- break;
- }
- c.row += ctrl[j].row;
- c.col += ctrl[j].col;
- }
- if(found){ /// Reverse
- c.row -= ctrl[j].row;
- c.col -= ctrl[j].col;
- while(c.row != tr.row || c.col != tr.col){
- if(table[c.row][c.col] == 3 - p){
- table[c.row][c.col] = p;
- }
- c.row -= ctrl[j].row;
- c.col -= ctrl[j].col;
- }
- }
- }
- }
- PrintTable();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement