-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuva10010.cpp
108 lines (103 loc) · 1.88 KB
/
uva10010.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdio>
char table[50][50];
int inputlen;
int sizex,sizey;
class pos
{
private:
int x,y;
public:
pos(int origx,int origy):x(origx),y(origy){}
int getchar()
{
return table[x][y];
}
pos move(pos dst)
{
x+=dst.x;
y+=dst.y;
return *this;
}
bool _test(pos dst,char * input)
{
for( int i=0 ; i<inputlen ;++i )
{
if(x==0||x==sizex+1||y==0||y==sizey+1) return 0;
if(*input!=getchar()) return 0;
++input;
move(dst);
}
return 1;
}
bool test(pos dst,char * input)
{
pos tmp=*this;
bool value=_test(dst, input);
*this=tmp;
//std::cout<<value<<" "<<tmp.x<<tmp.y<<std::endl;
return value;
}
};
int main()
{
pos up(-1,0);
pos down(1,0);
pos left(0,-1);
pos right(0,1);
pos lu(-1,-1);
pos ld(1,-1);
pos ru(-1,1);
pos rd(1,1);
int n;
std::cin>>n;
while(n--)
{
//std::cin>>sizex>>sizey;
scanf("%d%d",&sizex,&sizey);//std::cin>>testnum;
for( int x=1 ; x<=sizex ; ++x )
{
for( int y=1 ; y<=sizey ; ++y )
{
std::cin>>table[x][y];
table[x][y]=toupper(table[x][y]);
}
}
int testnum;
scanf("%d",&testnum);//std::cin>>testnum;
char input[50];
while(testnum--)
{
//fgets(input,50,stdin);//scanf("%s",input);scanf("%s",input);
scanf("%s",input);
inputlen=strlen(input);
for( int i=0 ; i!=strlen(input) ; ++i )
{
input[i]=toupper(input[i]);
}
for( int x=1 ; x<=sizex ; ++x )
{
for( int y=1 ; y<=sizey ; ++y )
{
pos test(x,y);
if ( test.test(up ,input)||
test.test(down,input)||
test.test(left,input)||
test.test(right,input)||
test.test(lu,input)||
test.test(ld,input)||
test.test(ru,input)||
test.test(rd,input))
{
std::cout<<x<<" "<<y<<std::endl;
x=sizex+1;
y=sizey+1;
}
}
}
}
if (n) std::cout<<std::endl;
}
}