-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathP16268_ca_F015A._Cojones_del_Anticristo.cc
49 lines (40 loc) · 1.28 KB
/
P16268_ca_F015A._Cojones_del_Anticristo.cc
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
#include <bits/stdc++.h>
using namespace std;
int m, n;
vector <string> sopa;
#define coord pair <int,int>
struct Info {
string par;
int num; // comptador d’aparicions
bool operator<(const Info& p) {
if (num == p.num) return (par < p.par);
return (num > p.num);
}
};
bool match(const string& s, const int& x, const int& y, const coord& des, size_t p=0) {
if (p==s.size()) return true;
if (x >= m or y >= n) return false;
if (sopa[x][y] != s[p]) return false;
return match(s,x+des.first, y + des.second,des,p+1);
}
int main () {
int x;
while (cin >> x) {
vector <Info> noms (x);
for (int i = 0; i < x; ++i) cin >> noms[i].par;
cin >> m >> n;
sopa = vector <string> (m, string(n,' '));
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j) cin >> sopa[i][j];
for (int i=0; i < m; ++i) {
for (int j=0; j < n; ++j) {
for (size_t k = 0; k < noms.size(); ++k) {
noms[k].num += match(noms[k].par,i,j,{0,1});
noms[k].num += match(noms[k].par,i,j,{1,0});
}
}
}
sort(noms.begin(), noms.end());
for (const auto& i : noms) cout << i.num << ' ' << i.par << endl;
}
}