Pagini recente » Cod sursa (job #271612) | Cod sursa (job #2118345) | Cod sursa (job #1916935) | Cod sursa (job #1293120) | Cod sursa (job #50172)
Cod sursa(job #50172)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define nmax 1005
char a[nmax][nmax],b[nmax][nmax];
int t[nmax][nmax],n,m,nrmat,rez[nmax][nmax],lit[26];
void citire()
{
int i,j;
freopen("matrix.in", "r", stdin);
scanf("%d %d",&m,&n);
for (i=1; i<=m; i++)
gets(a[i]);
for (i=1; i<=n; i++)
{
gets(b[i]);
for (j=0; j<strlen(b[i]); j++)
lit[int(b[i][j]) - int('0')]+=1;
}
fclose(stdin);
}
void calc()
{
int i,j,x,c;
for (c=0; i<=26; i++)
{
memset(t,0,sizeof(t));
for (i=0; i<m; i++)
for (j=0; j<n; j++)
{
t[i][j] = t[i-1][j] + t[i][j-1] - t[i-1][j-1];
if (int(a[i][j])-int ('0') == c)
t[i][j] +=1;
for (i=n; i <= m ; i++)
for (j=n; j <= m ; j++ )
{
x=t[i][j]-t[i-n][j] - t[i-n][j-n];
if ( x != lit[c] )
rez[i][j]=1;
}
}
}
for (i=n; i<=m; i++ )
for (j=n; j<=m; j++)
if (rez[i][j] == 0)
nrmat+=1;
}
int main ()
{
citire();
calc();
freopen("matrix.out","w",stdout);
printf("%d",nrmat);
fclose(stdout);
return 0;
}