On the board 4 * 4 sub Reversi filled, the position and the number of black and white random coordinates where the upper left corner (1,1), the bottom right coordinates (4,4), there are now sequentially reversing operation, to Some coordinates given pivot up and down the center of the four pieces of color inversion, calculate the color of the board after inversion.
Enter a description:
Given two arrays, two rows
First row are the initial board, a 4 * 4 matrix, wherein 0 represents white pieces, black pieces 1 represents
The second line inverted position, in which a total of three inverted position
Output Description:
Please return to the board after the flip, a 4 * 4 matrix
Example 1
Entry
[[0,0,1,1],[1,0,1,0],[0,1,1,0],[0,0,1,0]] [[2,2],[3,3],[4,4]]
Export
[[0,1,1,1],[0,0,1,0],[0,1,1,0],[0,0,1,0]]
#include <iostream> #include <vector> using namespace std; int main() { string input; cin.get(); int n = 2; vector<vector<char>> qipan; vector<vector<int>> caozuo; vector<char> temp1; vector<int> temp2; while (n--) { getline(cin, input); for(int i = 0; i < input.size(); i++){ if(n == 1){ if(input[i] == '0' || input[i] == '1'){ temp1.push_back(input[i]); } if(temp1.size() == 4){ qipan.push_back(temp1); temp1.clear(); } } else{ if(input[i] != '[' && input[i] != ']' && input[i] != ','){ temp2.push_back((int)input[i] - '0'); } if(temp2.size() == 2){ caozuo.push_back(temp2); temp2.clear(); } } } } for(int i = 0; i < caozuo.size(); i++){ int row = caozuo[i][0]-1; int col = caozuo[i][1]-1; if(0<=row-1 && row-1<=3) qipan[row-1][col] = qipan[row-1][col] == '0' ? '1' : '0'; if(0<=row+1 && row+1<=3) qipan[row+1][col] = qipan[row+1][col] == '0' ? '1' : '0'; if(0<=col-1 && col-1<=3) qipan[row][col-1] = qipan[row][col-1] == '0' ? '1' : '0'; if(0<=col+1 && col+1<=3) qipan[row][col+1] = qipan[row][col+1] == '0' ? '1' : '0'; } cout.put('['); for(int i = 0; i < qipan.size(); i++){ cout.put('['); for(int j = 0; j < qipan[i].size(); j++){ cout.put(qipan[i][j]); if(j != 3) cout.put(','); } cout.put(']'); if(i != 3) cout.put(','); } cout.put(']'); return 0; }