-
Notifications
You must be signed in to change notification settings - Fork 3
/
422-Word-SearchWonder.cpp
executable file
·86 lines (77 loc) · 2.18 KB
/
422-Word-SearchWonder.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
//
// 422 - Word-Search Wonder.cpp
// Uva
//
// Created by Alexander Faxå on 2012-02-13.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
using namespace std;
int l, length;
char c[101][101];
string s;
bool is_at(int x, int y, int i, int dx, int dy)
{
// cout << sizeof(s) << endl;
if (i == s.length())
return true;
if(x < 0 || y < 0 || x >= l || y >= l || c[x][y] != s[i])
return false;
else
return is_at(x+dx,y+dy,i+1,dx,dy);
}
void find()
{
for (int i = 0; i < l; i++) {
for (int j = 0; j < l; j++) {
if(is_at(i, j, 0, 1, 0)){
cout << i+1 << "," << j+1 << " " << i+length << "," << j+1 << endl;
return;
}
if(is_at(i, j, 0, -1, 0)){
cout << i+1 << "," << j+1 << " " << i+2-length << "," << j+1 << endl;
return;
}
if(is_at(i, j, 0, 0, 1)){
cout << i+1 << "," << j+1 << " " << i+1 << "," << j+length << endl;
return;
}
if(is_at(i, j, 0, 0, -1)){
cout << i+1 << "," << j+1 << " " << i+1 << "," << j+2-length << endl;
return;
}
if(is_at(i, j, 0, 1, 1)){
cout << i+1 << "," << j+1 << " " << i+length << "," << j+length << endl;
return;
}
if(is_at(i, j, 0, 1, -1)){
cout << i+1 << "," << j+1 << " " << i+length << "," << j+2-length << endl;
return;
}
if(is_at(i, j, 0, -1, 1)){
cout << i+1 << "," << j+1 << " " << i+2-length << "," << j+length << endl;
return;
}
if(is_at(i, j, 0, -1, -1)){
cout << i+1 << "," << j+1 << " " << i+2-length << "," << j+2-length << endl;
return;
}
}
}
cout << "Not found" << endl;
}
int main()
{
cin >> l;
for(int i = 0; i < l; i++)
for(int j = 0; j < l; j++)
cin >> c[i][j];
while(true)
{
cin >> s;
length = s.length();
if(s == "0") break;
find();
}
return 0;
}