Pagini recente » Cod sursa (job #2068825) | Cod sursa (job #30816) | Cod sursa (job #2982531) | Cod sursa (job #2084355) | Cod sursa (job #4852)
Cod sursa(job #4852)
var f:text;
ok:boolean;
m,n,i,j,sol:integer;
c:char;
a:array[1..1000,1..1000] of char;
b:array[0..1000,0..1000,'a'..'z'] of longint;
h:array['a'..'z'] of longint;
begin
sol:=0;
assign(f,'matrix.in');
reset(f);
readln(f,m,n);
for i:=1 to m do
begin
for j:=1 to m do begin
read(f,a[i,j]);
for c:='a' to 'z' do b[i,j,c]:=b[i-1,j,c]+b[i,j-1,c]-b[i-1,j-1,c];
inc(b[i,j,a[i,j]]);
end;
readln(f);
end;
for i:=1 to n do
begin
for j:=1 to n do begin
read(f,c);
inc(h[c]);
end;
readln(f);
end;
close(f);
for i:=n to m do
for j:=n to m do begin
ok:=true;
for c:='b' to 'z' do
if b[i,j,c]-b[i-n,j,c]-b[i,j-n,c]+b[i-n,j-n,c]<>h[c] then begin
ok:=false;
break;
end;
if ok then inc(sol);
end;
assign(f,'matrix.out');
rewrite(f);
writeln(f,sol);
close(f);
end.