Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int route[10];
- char str[10][10];
- string store = "IEHOVA#";
- int n,m;
- int dx[] = {-1,0,0};
- int dy[] = {0,1,-1};
- void solve(int x,int y,int dir)
- {
- if(dir==7)
- {
- for(int j=0;j<7;j++)
- {
- if(j>0)
- printf(" ");
- if(route[j]==0)
- {
- printf("forth");
- }
- else if(route[j]==1)
- {
- printf("right");
- }
- else
- {
- printf("left");
- }
- }
- puts("");
- return;
- }
- for(int i=0;i<3;i++)
- {
- int u = x+dx[i];
- int v = y+dy[i];
- if(u>=n || v>=m || u<0 || v<0 || str[u][v]!=store[dir])
- continue;
- route[dir] = i;
- solve(u,v,dir+1);
- }
- }
- int main()
- {
- int test,i;
- scanf("%d",&test);
- while(test--)
- {
- scanf("%d%d",&n,&m);
- getchar();
- for(i=0;i<n;i++)
- {
- gets(str[i]);
- }
- for(i=0;i<m;i++)
- {
- if(str[n-1][i]=='@')
- {
- solve(n-1,i,0);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment