Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef vector<char> Row;
- typedef vector<Row> Board;
- Board read_board(int n) {
- Board b(n, Row(n));
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- cin >> b[i][j];
- }
- }
- return b;
- }
- void write_menace(int i1, int j1, int i2, int j2) {
- cout << "(" << i1 << "," << j1 << ") <--> (" << i2 << "," << j2 << ")" <<endl;
- }
- void find_menaces(const Board & b, int ib, int jb) {
- int n = b.size();
- int i = ib;
- int j = jb;
- bool found = false;
- while (i < n-1 and j > 0 and not found){
- // BOTTOM LEFT
- ++i;
- --j;
- if (b[i][j] == 'B'){
- found = true;
- write_menace(ib, jb, i, j);
- }
- }
- i = ib;
- j = jb;
- found = false;
- while (i < n-1 and j < n-1 and not found){
- // BOTTOM RIGHT
- ++i;
- ++j;
- if (b[i][j] == 'B'){
- found = true;
- write_menace(ib, jb, i, j);
- }
- }
- }
- void check_board(const Board& b) {
- int n = b.size();
- for (int i = 0; i < n; ++i){
- for (int j = 0; j < n; ++j){
- if (b[i][j] == 'B') find_menaces(b, i, j);
- }
- }
- }
- int main() {
- int n;
- int bn = 1;
- while (cin >> n) {
- Board b = read_board(n);
- cout << "board num " << bn << endl;
- ++bn;
- check_board(b);
- cout << "----------------" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement