Pagini recente » Cod sursa (job #647608) | Cod sursa (job #350590) | Cod sursa (job #2369695) | Cod sursa (job #2967823) | Cod sursa (job #3165461)
#include <iostream>
#include <fstream>
#include <deque>
#include <algorithm>
#include <cmath>
#include <vector>
#include <climits>
#define DIM 1000
using namespace std;
//ifstream f("in.in");
//ofstream g("out.out");
ifstream f("matrix.in");
ofstream g("matrix.out");
int n,m,sol;
bool ok;
int a[DIM+5][DIM+5][30],v[30];
char c;
signed main()
{
f>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
f>>c;
for(int k=1;k<=26;k++){
a[i][j][k] = a[i][j-1][k] + a[i-1][j][k] - a[i-1][j-1][k];
}
a[i][j][c-'a'+1]++;
}
}
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
f>>c;
v[c-'a'+1]++;
}
}
/*for(int i=1;i<=4;i++){
cout<<v[i]<<" ";
}
cout<<'\n'<<'\n';
for(int k=1;k<=4;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j][k]<<" ";
}
cout<<'\n';
}
cout<<'\n';
}*/
for(int i=m;i<=n;i++){
for(int j=m;j<=n;j++){
ok = 1;
for(int k=1;k<=26;k++){
if(a[i][j][k] - a[i][j-m][k] - a[i-m][j][k] + a[i-m][j-m][k] != v[k]){
ok = 0;
break;
}
}
if(ok){
//cout<<i<<" "<<j<<'\n';
sol++;
}
}
}
g<<sol;
return 0;
}