#include<bits/stdc++.h>
#define N 2000
using namespace std;
char a[N][N], b[N][N], c[N][N];
int matching(int n1, int n2)
{
int i, j, i1, j1, cnt = 0;
for(i=0;i<n1-n2+1;i++)
{
for(j=0;j<n1-n2+1;j++)
{
int f = 1;
for(i1=0; i1<n2; i1++)
{
for(j1=0; j1<n2; j1++)
{
if(a[i+i1][j+j1] != c[i1][j1])
{
f = 0;
break;
}
}
if(f == 0)
break;
}
if(f == 1)
cnt++;
}
}
return cnt++;
}
void feelings(int n1, int n2)
{
int i, j, cnt = 0;
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[i][j] = b[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << " ";
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[j][n2-i-1] = b[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
b[i][j] = c[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << " ";
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[j][n2-i-1] = b[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
b[i][j] = c[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << " ";
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[j][n2-i-1] = b[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << "\n";
}
int main()
{
int n1, n2, i, j;
while(cin >> n1 >> n2 and n1 != 0 and n2 != 0)
{
for(i=0;i<n1;i++)
{
for(j=0;j<n1;j++)
{
cin >> a[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
cin >> b[i][j];
}
}
feelings(n1, n2);
}
return 0;
}
#define N 2000
using namespace std;
char a[N][N], b[N][N], c[N][N];
int matching(int n1, int n2)
{
int i, j, i1, j1, cnt = 0;
for(i=0;i<n1-n2+1;i++)
{
for(j=0;j<n1-n2+1;j++)
{
int f = 1;
for(i1=0; i1<n2; i1++)
{
for(j1=0; j1<n2; j1++)
{
if(a[i+i1][j+j1] != c[i1][j1])
{
f = 0;
break;
}
}
if(f == 0)
break;
}
if(f == 1)
cnt++;
}
}
return cnt++;
}
void feelings(int n1, int n2)
{
int i, j, cnt = 0;
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[i][j] = b[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << " ";
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[j][n2-i-1] = b[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
b[i][j] = c[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << " ";
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[j][n2-i-1] = b[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
b[i][j] = c[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << " ";
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
c[j][n2-i-1] = b[i][j];
}
}
cnt = matching(n1, n2);
cout << cnt << "\n";
}
int main()
{
int n1, n2, i, j;
while(cin >> n1 >> n2 and n1 != 0 and n2 != 0)
{
for(i=0;i<n1;i++)
{
for(j=0;j<n1;j++)
{
cin >> a[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
cin >> b[i][j];
}
}
feelings(n1, n2);
}
return 0;
}
Comments
Post a Comment