Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- char a[110][110];
- int main()
- {
- ll n, m, x = 0, y = 0, i, j;
- cin >> n >> m;
- for(int i = 0; i < n; i++)
- for(int j = 0; j < m; j++)
- {
- cin >> a[i][j];
- if(a[i][j] == '#' && a[x][y] != '#')
- {
- x = i;
- y = j;
- }
- }
- cout << x << ' ' << y << endl;
- x--;
- y--;
- i = x;
- j = y + 1;
- while(x != i || y != j)
- {
- if(a[i + 1][j] == '#')
- {
- cout << i + 1 << ' ' << 1 + j << endl;
- j++;
- }
- else if(a[i - 1][j] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- j--;
- }
- else if(a[i][j - 1] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- i++;
- }
- else if(a[i][j + 1] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- i--;
- }
- else if(a[i + 1][j - 1] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- i++;
- }
- else if(a[i - 1][j - 1] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- j--;
- }
- else if(a[i - 1][j + 1] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- i--;
- }
- else if(a[i + 1][j + 1] == '#')
- {
- cout << 1 + i << ' ' << 1 + j << endl;
- j++;
- }
- }
- return 0;
- }
- /*
- 5 4
- ....
- ..#.
- .##.
- ..#.
- ....
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement