Pagini recente » Cod sursa (job #2110050) | Cod sursa (job #617889) | Cod sursa (job #2577678) | Cod sursa (job #2493594) | Cod sursa (job #2243621)
#include <fstream>
#define DIM 1002
using namespace std;
ifstream in ("matrix.in");
ofstream out("matrix.out");
int matHumanDim, matVirusDim, virusApparitions[200], virusCurrentApparitions[200], letterUp[DIM][DIM], ans;
char letter, matHuman[DIM][DIM];
int main(int argc, const char * argv[]) {
in>>matHumanDim>>matVirusDim;
for(int cntLin = 1; cntLin <= matHumanDim; ++ cntLin)
for(int cntCol = 1; cntCol <= matHumanDim; ++ cntCol)
in>>matHuman[cntLin][cntCol];
for(int cntLin = 1; cntLin <= matVirusDim; ++ cntLin){
for(int cntCol = 1; cntCol <= matVirusDim; ++ cntCol){
in>>letter;
++ virusApparitions[letter];
}
}
for(int cntLin = 1; cntLin <= matHumanDim; ++ cntLin){
for(int cnt = 'a'; cnt <= 'z'; ++ cnt){
virusCurrentApparitions[cnt] = 0;
}
for(int cntCol = 1; cntCol <= matHumanDim; ++ cntCol){
//++ virusCurrentApparitions[matHuman[cntLin][cntCol]];
++ letterUp[cntCol][matHuman[cntLin][cntCol]];
if(cntLin - matVirusDim >= 0){
if(cntLin - matVirusDim >= 1){
-- letterUp[cntCol][matHuman[cntLin - matVirusDim][cntCol]];
//-- matHuman[cntLin - matVirusDim][cntCol];
}
for(int cnt = 'a'; cnt <= 'z'; ++ cnt){
virusCurrentApparitions[cnt] += letterUp[cntCol][cnt];
}
if(cntCol - matVirusDim >= 1){
for(int cnt = 'a'; cnt <= 'z'; ++ cnt){
virusCurrentApparitions[cnt] -= letterUp[cntCol - matVirusDim][cnt];
}
}
if(cntCol - matVirusDim >= 0){
bool validation = true;
for(int cnt = 'a'; cnt <= 'z'; ++ cnt){
if(virusCurrentApparitions[cnt] != virusApparitions[cnt])
validation = false;
}
if(validation)
++ ans;
}
}
}
}
out<<ans;
return 0;
}