Pagini recente » Cod sursa (job #3263037) | Cod sursa (job #1450896) | Cod sursa (job #2698561) | Cod sursa (job #2612478) | Cod sursa (job #1876026)
#include <bits/stdc++.h>
#define nmax 1001
using namespace std;
ifstream fin("matrix.in");
ofstream fout("matrix.out");
int n,m,rez,ap[27],d[nmax][nmax],bst[nmax][nmax];
char s[nmax][nmax];
int main()
{
int i,j,k;
char x;
fin>>n>>m;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
fin>>s[i][j];
for(i=1; i<=m; i++)
for(j=1; j<=m; j++)
{
fin>>x;
ap[x-96]++;
}
fin.close();
for(k=1; k<=26; k++)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
d[i][j]=d[i-1][j]-d[i-1][j-1]+d[i][j-1];
if(s[i][j]==k+96)
d[i][j]++;
if(i>=m && j>=m && d[i][j]-d[i-m][j]-d[i][j-m]+d[i-m][j-m]!=ap[k])
bst[i][j]=1;
}
}
}
for(i=m; i<=n; i++)
for(j=m; j<=n; j++)
if(!bst[i][j])
rez++;
fout<<rez;
fout.close();
return 0;
}