VBGRASS - Bãi cỏ ngon nhất

Tác giả: ll931110

Ngôn ngữ: Pascal

Program VBGRASS;
        Const
                input  = '';
                output = '';
        Var
                a: array[1..101,1..101] of boolean;
              r,c: integer;

Procedure init;
          Var
                 f: text;
                ch: char;
               i,j: integer;
          Begin
                Assign(f, input);
                        Reset(f);
                                Fillchar(a, sizeof(a), false);
                                Readln(f, r, c);
                                For i:= 1 to r do
                                    Begin
                                        For j:= 1 to c do
                                                Begin
                                                        Read(f, ch);
                                                        If ch = '#' then a[i,j]:= true;
                                                End;
                                        Readln(f);
                                    End;
                Close(f);
          End;


Procedure solve;
          Var
                    f: text;
                k,i,j: integer;
          Begin
                Assign(f, output);
                        Rewrite(f);
                                k:= 0;
                                For i:= 1 to r do
                                        For j:= 1 to c do
                                                If a[i,j] then
                                                        Begin
                                                              a[i,j]:= false;
                                                              inc(k);

                                                              If a[i, j + 1] then a[i, j + 1]:= false;
                                                              If a[i + 1, j] then a[i + 1, j]:= false;
                                                        End;
                                Writeln(f, k);
                Close(f);
          End;

Begin
        init;
        solve;
End.

Download