Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, x, y;
- char c[200][200];
- bool u[200][200];
- int main() {
- cin >> n;
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- cin >> c[i][j];
- }
- }
- cin >> x >> y;
- while (1) {
- if (x > n || x < 1 || y > n || y < 1) {
- puts("0");
- break;
- }
- if (u[x][y]) {
- puts("-1");
- break;
- }
- if (c[x][y] == '.') {
- cout << x << " " << y << endl;
- break;
- }
- u[x][y] = 1;
- if (c[x][y] == 'N') x--;
- if (c[x][y] == 'S') x++;
- if (c[x][y] == 'E') y++;
- if (c[x][y] == 'W') y--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement