Pagini recente » Cod sursa (job #2902064) | Cod sursa (job #177288) | Cod sursa (job #1778366) | Cod sursa (job #88037) | Cod sursa (job #282232)
Cod sursa(job #282232)
{Arhiva de probleme - Matrix}
const
dim = 1010;
var
n,m,i,j : longint;
f: text;
t: char;
c: array[1..dim,1..dim] of char;
a: array[0..dim,0..dim] of longint;
b: array[1..dim,1..dim] of boolean;
x: array['a'..'z'] of longint;
begin
assign(f, 'matrix.in');
reset(f);
readln(f, n, m);
for i := 1 to n do
begin
for j := 1 to n do
read(f,c[i,j]);
readln(f);
end;
for i :=1 to m do
begin
for j:=1 to m do
begin
read(f,t);
inc(x[t]);
end;
readln(f);
end;
close(f);
for i:=1 to n do for j:=1 to n do
if (i>=m) and (j>=m) then
b[i,j]:=true
else
b[i,j] := false;
for t := 'a' to 'z' do
begin
{ for i:=1 to n do for j:=1 to n do a[i,j] := 0;}
fillchar(a, sizeof(a), 0);
for i:=1 to n do for j:=1 to n do
begin
if c[i,j] = t then
a[i,j]:= a[i,j-1] + a[i-1, j] - a[i-1,j-1] + 1
else
a[i,j]:= a[i,j-1] + a[i-1, j] - a[i-1,j-1];
if (i>=m) and (j>=m) then
if (a[i,j]-a[i-m,j]-a[i,j-m]+a[i-m,j-m] <> x[t]) then
b[i,j] := false;
end;
end;
m := 0;
for i:=1 to n do for j:=1 to n do
if (b[i,j]) then
inc(m);
assign(f,'matrix.out');
rewrite(f);
writeln(f,m);
close(f);
end.