Pagini recente » Cod sursa (job #2045206) | Cod sursa (job #1055828) | Cod sursa (job #1781044) | Cod sursa (job #2007173) | Cod sursa (job #770503)
Cod sursa(job #770503)
Program matrix;
var a:array [0..1001,0..1001] of char;
aux:array [0..1001,0..1001] of longint;
sol:array [1..1001,1..1001] of byte;
v:array ['a'..'z'] of longint;
s:array [1..1001] of char;
b1:array [1..1 shl 17] of char;
ch:char;
n,m,i,j,nr:longint;
fi,fo:text;
procedure solve;
var i,j,k:longint;
begin
fillchar(aux,sizeof(aux),0);
for i:=1 to m do
for j:=1 to m do
if a[i,j]=ch then aux[i,j]:=1+aux[i-1,j]+aux[i,j-1]-aux[i-1,j-1]
else aux[i,j]:=aux[i-1,j]+aux[i,j-1]-aux[i-1,j-1];
for i:=n to m do
for j:=n to m do begin
if aux[i,j]-aux[i-n,j]-aux[i,j-n]+aux[i-n,j-n]=v[ch] then inc(sol[i,j]);
if sol[i,j]=26 then inc(nr);
end;
end;
begin
assign(fi,'matrix.in');
assign(fo,'matrix.out');
settextbuf(fi,b1);
reset(fi); rewrite(fo); readln(fi,m,n);
for i:=1 to m do begin
readln(fi,s);
for j:=1 to m do a[i,j]:=s[j];
end;
for i:=1 to n do begin
for j:=1 to n do begin read(fi,ch); inc(v[ch]); end;
readln(fi);
end;
for ch:='a' to 'z' do solve;
write(fo,nr);
close(fo);
end.