Pagini recente » Cod sursa (job #3197224) | Cod sursa (job #3332557) | Cod sursa (job #3197219) | Cod sursa (job #3349137) | Cod sursa (job #3346588)
#include <fstream>
#define NMAX 1002
using namespace std;
ifstream fin("matrix.in");
ofstream fout("matrix.out");
int N,M,fb[27],Sp[NMAX][NMAX];
char A[NMAX][NMAX],ok[NMAX][NMAX];
void citire()
{
fin>>M>>N;
for(int i=1; i<=M; i++)
{
for(int j=1; j<=M; j++)
{
fin>>A[i][j];
}
}
char ch;
for(int i=1; i<=N; i++)
{
for(int j=1; j<=N; j++)
{
fin>>ch;
fb[ch-'a']++;
}
}
}
int main()
{
citire();
for(int i=N; i<=M; i++)
{
for(int j=N; j<=M; j++)
{
ok[i][j]=1;
}
}
for(int c=0; c<=25; c++)
{
for(int i=1; i<=M; i++)
{
for(int j=1; j<=M; j++)
{
int cost=0;
if(A[i][j]-'a'==c)
{
cost=1;
}
Sp[i][j]=cost+Sp[i-1][j]+Sp[i][j-1]-Sp[i-1][j-1];
}
}
for(int i=N; i<=M; i++)
{
for(int j=N; j<=M; j++)
{
if(Sp[i][j]-Sp[i-N][j]-Sp[i][j-N]+Sp[i-N][j-N]!=fb[c])
{
ok[i][j]=0;
}
}
}
}
int ans=0;
for(int i=N; i<=M; i++)
{
for(int j=N; j<=M; j++)
{
ans+=ok[i][j];
}
}
fout<< ans << "\n";
return 0;
}