-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRapigramaN2
70 lines (59 loc) · 1.3 KB
/
RapigramaN2
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
//Timing: 26:55
#include <bits/stdc++.h>
#define MAX 10000
using namespace std;
int n,m;
string a;
vector< vector< char > > ad(MAX, vector<char> (MAX));
vector< string > lista;
string r(string s){
string temp="";
for(int i=0;i<s.size();i++)
temp+=s[(s.size()-1)-i];
return temp;
}
char gp(string s){
string temp;
for(int i=1;i<=n;i++){
temp = "";
for(int j=1;j<=n;j++)
temp+=ad[i][j];
if(temp.find(s) != string::npos)
return 'E';
else {
temp = r(temp);
if(temp.find(s) != string::npos)
return 'O';
}
}
for(int i=1;i<=n;i++){
temp = "";
for(int j=1;j<=n;j++)
temp+=ad[j][i];
if(temp.find(s) != string::npos)
return 'S';
else {
temp = r(temp);
if(temp.find(s) != string::npos)
return 'N';
}
}
return '0';
}
int main(){
ifstream fin("in.txt");
fin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
fin >> ad[i][j];
}
}
while(fin >> a)
lista.push_back(a);
char t;
for(int i=0;i<lista.size();i++){
t = gp(lista[i]);
if(t != '0')
cout << i+1 << ' ' << t << endl;
}
}