Pagini recente » Cod sursa (job #2419557) | Cod sursa (job #1671764) | Cod sursa (job #2352760) | Cod sursa (job #723241) | Cod sursa (job #1145412)
#include <fstream>
#define lmax 1001
using namespace std;
ifstream f("matrix.in");
ofstream g("matrix.out");
bool ok;
char c;
int i,j,k,n,m,nr;
int v[27];
int a[lmax][lmax][26];
int main()
{
f>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
f>>c;
a[i][j][c-96]++;
for (k=1;k<=26;k++)
a[i][j][k]+=a[i-1][j][k]+a[i][j-1][k]-a[i-1][j-1][k];
}
for (i=1;i<=m;i++)
for (j=1;j<=m;j++)
{
f>>c;
v[c-96]++;
}
for (i=m;i<=n;i++)
for (j=m;j<=n;j++)
{
ok=1;
for (k=1;k<=26;k++)
if (v[k]!=a[i][j][k]-a[i-m][j][k]-a[i][j-m][k]+a[i-m][j-m][k])
ok=0;
if (ok)
nr++;
}
g<<nr;
f.close();
g.close();
}