-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva_10452_Marcus.cpp
91 lines (73 loc) · 2.1 KB
/
uva_10452_Marcus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<bits/stdc++.h>
#define pb(n) push_back(n)
#define bug cout<<"bug";
#define all(c) c.begin(),c.end()
#define fr(i,n) for(i=0;i<n;i++)
#define sf(n) scanf("%d",&n)
#define mst(n) memset(n,0,sizeof(n))
#define nl printf("\n")
#define lli long long int
#define tr(container,it) \
for (auto it = container.begin(); it != container.end() ; ++it)
#define INF INT_MAX
#define MOD 1000000007
#define mp(i,j) make_pair(i,j)
#define infile freopen("in.txt","r",stdin)
#define outfile freopen("out.txt","w",stdout)
#define pr(a) cout<<cout<<a.a.first<<" "<< a.a.second<<endl
#define V 5
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pi;
inline bool valid(pi a,int len,int wid)
{
return (a.fi>=0 && a.fi<len && a.se>=0 && a.se<wid);
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
char ara[8][8];
int dirx[3]= {-1,0,0},diry[3]= {0,1,-1};
int len,wid;
pi src,des;
scanf("%d %d\n",&len,&wid);
for(int i=0; i<len; i++)
{
for(int j=0; j<wid; j++)
{
scanf("%c",&ara[i][j]);
if(ara[i][j]=='@') src.fi=i, src.se=j ;
if(ara[i][j]=='#') des.fi=i,des.se=j ;
}
getchar();
}
char str[]="IEHOVA#";
int order=0;
while(src!=des)
{
pi tmp=src;
for(int i=0; i<3; i++)
{
tmp.fi+=dirx[i],tmp.se+=diry[i];
if(valid(tmp,len,wid))
{
if(ara[tmp.fi][tmp.se]==str[order])
{
order++;
if(i==0) printf("forth");
else if(i==1) printf("right");
else if(i==2) printf("left");
src=tmp;
if(src!=des) printf(" ");
}
}
tmp.fi-=dirx[i],tmp.se-=diry[i];
}
}
nl;
}
}