Pagini recente »
Borderou de evaluare (job #102007)
|
Istoria paginii runda/clasa6_3
|
Istoria paginii runda/lasm_15_01_cl10_2/clasament
|
test_cerc_clasa_a_7-a
|
Cod sursă (job #388926)
Cod sursă (job
#388926)
#include <fstream>
using namespace std;
ifstream in("fotografie.in");
ofstream out("fotografie.out");
int n, m, p, q;
const int MOD = 666013;
const int base = 31;
int hashes[1001][1001];
int hashes2[1001][1001];
int put[1001];
char ch;
int main()
{
in >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
in >> ch;
hashes[i][j] = (hashes[i][j-1]*base+(ch-'a'))%MOD;
}
}
put[0]=1;
for(int i = 1; i <= n; i++)
put[i] = (put[i-1]*base)%MOD;
in >> p >> q;
for(int i = 1; i <= p; i++)
{
for(int j = 1; j <= q; j++)
{
in >> ch;
hashes2[i][j] = (hashes2[i][j-1]*base+(ch-'a'))%MOD;
}
}
for(int i = 1; i <= n-p+1; i++)
{
for(int j = 1; j <= m-q+1; j++)
{
bool ok=true;
for(int k = 1; k <= p && ok; k++)
{
if(((hashes[i+k-1][j+q-1]-hashes[i+k-1][j-1]*put[q])%MOD+MOD)%MOD != hashes2[k][q])
ok = false;
}
if(ok)
out << i-1 << ' ' << j-1 << '\n';
}
}
return 0;
}