-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1101.cpp
56 lines (56 loc) · 1.19 KB
/
P1101.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
#include <bits/stdc++.h>
using namespace std;
int n;
string word = "yizhong";
int x_change[] = {1, 0, -1, 0, 1, -1, 1, -1};
int y_change[] = {0, 1, 0, -1, 1, -1, -1, 1};
string martx[105];
bool isword[101][101];
bool findword(int i, int j, int di, int dj, int next)
{
if (next >= 7)
{
return true;
}
if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < n && martx[i + di][j + dj] == word[next])
{
if (findword(i + di, j + dj, di, dj, next + 1))
{
isword[i + di][j + dj] = true;
return 1;
}
}
return 0;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> martx[i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < 8; k++)
{
findword(i - x_change[k], j - y_change[k], x_change[k], y_change[k], 0);
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (isword[i][j])
{
cout << martx[i][j];
}
else
cout << "*";
}
cout << endl;
}
return 0;
}