Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
- int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
- char grid[100][100];
- int visited[100][100];
- queue<pair<char, pair<int, int>>> blade, vampire;
- bool isBlade(int i, int j) {
- if (grid[i][j] == 'A' || grid[i][j] == 'B' || grid[i][j] == 'C')
- return true;
- else
- return false;
- }
- bool isVampire(int i, int j) {
- if (grid[i][j] == 'M' || grid[i][j] == 'N' || grid[i][j] == 'O')
- return true;
- else
- return false;
- }
- bool isValid(int i, int j, int row, int column) {
- if (i < 0 || i >= row || j < 0 || j >= column || grid[i][j] == 'X' || grid[i][j] == '-')
- return false;
- else
- return true;
- }
- void bfs(pair<int, int> start, int row, int column) {
- memset(visited, 0, sizeof(visited));
- queue<pair<int, int>> q;
- q.push(start);
- while (!q.empty()) {
- pair<int, int> top = q.front();
- q.pop();
- if (grid[top.first][top.second] == 'E')
- return;
- else if (isBlade(top.first, top.second))
- blade.push(make_pair(grid[top.first][top.second], make_pair(top.first, top.second)));
- else if (isVampire(top.first, top.second))
- vampire.push(make_pair(grid[top.first][top.second], make_pair(top.first, top.second)));
- if (!visited[top.first][top.second]) {
- for (int i = 0; i < 4; i++) {
- int r = top.first;
- int c = top.second;
- r += dx[i];
- c += dy[i];
- if (isValid(r, c, row, column) && visited[r][c] == 0) {
- q.push(make_pair(r, c));
- }
- }
- visited[top.first][top.second] = 1;
- }
- }
- }
- int main() {
- #ifdef TarekHasan
- freopen("input.txt", "r", stdin);
- #endif // TarekHasan
- int row, column;
- cin >> row >> column;
- pair<int, int> start;
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < column; j++) {
- cin >> grid[i][j];
- if (grid[i][j] == 'S')
- start = make_pair(i, j);
- }
- }
- bfs(start, row, column);
- cout << "Blade information: " << endl;
- ;
- while (!blade.empty()) {
- pair<char, pair<int, int>> top = blade.front();
- cout << top.first << " " << top.second.first << " " << top.second.second << endl;
- blade.pop();
- }
- cout << "Vampire information: " << endl;
- while (!vampire.empty()) {
- pair<char, pair<int, int>> top = vampire.front();
- cout << top.first << " " << top.second.first << " " << top.second.second << endl;
- vampire.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement