Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int n,m,p,a[100][100],i,j,d[10],di[]= {-1,-1,0,1,1,1,0,-1}, dj[]= {0,1,1,1,0,-1,-1,-1},li,ci,lf,cf;
- struct elemente
- {
- int l,c;
- } st[100];
- int valid(int p)
- {
- int ok=1;
- for(i=1; i<p; i++)
- if(st[i].l==st[p].l && st[i].c==st[p].c)
- ok=0;
- if(a[st[p].l][st[p].c]==1)
- ok=0;
- if(st[p].l<1 || st[p].l>m || st[p].c<1 || st[p].c>n)
- ok=0;
- return ok;
- }
- void tipar(int p)
- {
- for(i=1; i<=p; i++)
- {
- cout<<st[i].l<<" "<<st[i].c;
- cout<<endl;
- }
- cout<<endl;
- }
- int main()
- {
- ifstream f("date.in");
- f>>m>>n>>li>>ci>>lf>>cf;
- for(i=1; i<=m; i++)
- for(j=1; j<=n; j++)
- f>>a[i][j];
- p=1;
- st[p].l=li;
- st[p].c=ci;
- p=2;
- d[p]=-1;
- while(p>1)
- if(d[p]<7)
- {
- d[p]++;
- st[p].l=st[p-1].l+di[d[p]];
- st[p].c=st[p-1].c+dj[d[p]];
- if(valid(p)==1)
- if(st[p].l==lf && st[p].c==cf)
- tipar(p);
- else
- {
- p++;
- d[p]=-1;
- }
- } else p--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement