VBGRASS - Bãi cỏ ngon nhất

Tác giả: flashmt

Ngôn ngữ: Pascal

var m,n,re,i,j:longint;
    a:array[1..100] of string;
    d:array[1..100,1..100] of boolean;

begin
        readln(m,n);
        for i:=1 to m do readln(a[i]);
        for i:=1 to m do
            for j:=1 to n do
               if not d[i,j] and (a[i][j]='#') then
               begin
                    inc(re);
                    if (i<m) and (a[i+1,j]='#') then d[i+1,j]:=true;
                    if (j<n) and (a[i,j+1]='#') then d[i,j+1]:=true;
               end;
        writeln(re);
end.

Download