Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char niz[210][210];
- int xpoc, ypoc, xmeta,ymeta;
- int n, m , d,rjesx, rjesy;
- int resx, resy;
- bool provjera(int k)
- {
- if(k == 0)
- {
- xpoc--;
- while(xpoc >= 0)
- {
- xpoc--;
- if(niz[xpoc][ypoc] == '/' ) provjera(1);
- if(niz[xpoc][ypoc] == '\\') provjera(3);
- if(niz[xpoc][ypoc] == 'E') return 1;
- }
- }
- if(k== 1)
- {
- while(ypoc <= m)
- {
- ypoc ++;
- if(niz[xpoc][ypoc] == '/') provjera(0);
- if(niz[xpoc][ypoc] == '\\') provjera(2);
- if(niz[xpoc][ypoc] == 'E') return 1;
- }
- }
- if(k == 2)
- {
- while(xpoc <= n)
- {
- xpoc ++;
- if(niz[xpoc][ypoc] == '/') provjera(3);
- if(niz[xpoc][ypoc] == '\\') provjera(1);
- if(niz[xpoc][ypoc] == 'E') return 1;
- }
- }
- if(k == 3)
- {
- while(ypoc >= 0)
- {
- ypoc--;
- if(niz[xpoc][ypoc] == '/') provjera(2);
- if(niz[xpoc][ypoc] == '\\') provjera(0);
- if(niz[xpoc][ypoc] == 'E') return 1;
- }
- }
- return 0;
- }
- bool promjena()
- {
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m ; j++)
- {
- if(niz[i][j] == '/')
- {
- niz[i][j] = '\\';
- xpoc = resx;
- ypoc = resy;
- if(provjera(d) == 1)
- {
- rjesx = i+1;
- rjesy = j+1;
- return 1;
- }
- niz[i][j] = '/';
- }
- if (niz[i][j] == '\\' )
- {
- niz[i][j] = '/';
- xpoc = resx;
- ypoc = resy;
- if(provjera(d) == 1)
- {
- rjesx = i+1;
- rjesy = j+1;
- return 1;
- }
- niz[i][j] = '\\';
- }
- }
- }
- return 0;
- }
- int main()
- {
- cin >> n >> m;
- cin >> d;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- cin >> niz[i][j];
- if(niz [ i ][ j ] == 'E' )
- {
- xmeta = i;
- ymeta = j;
- }
- if (niz[i][j] == 'S')
- {
- xpoc = i;
- ypoc = j;
- }
- }
- }
- resx = xpoc;
- resy = ypoc;
- if(provjera(d) == 1) cout << "nije potrebno vrsiti izmjene" << endl;
- else
- {
- if(promjena() == 1) cout << rjesx << " " << rjesy << endl;
- else cout << "nemoguce" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement