Показать сообщение отдельно

  #5  
Старый 29.05.2007, 13:46
Joker-jar
Постоянный
Регистрация: 11.03.2007
Сообщений: 581
Провел на форуме:
4172659

Репутация: 646


Отправить сообщение для Joker-jar с помощью ICQ
По умолчанию

Вообще то, что ты дал не работает. Если только так:
Код:
program p1;

type
  arr=array[1..40000] of byte;

var
  n,m,i,j,count:integer;
  c:array[0..201,0..201] of char;
  first,last:word;
  ii,jj:^arr;
  input,output: text;

procedure put(i,j:integer);
   begin
      if c[i,j]='#' then begin
         inc(last);
         ii^[last]:=i;
         jj^[last]:=j;
         c[i,j]:='.';
      end;
   end;

   procedure get(var i,j:integer);
   begin
      i:=ii^[first];
      j:=jj^[first];
      inc(first);
   end;

   procedure paint(i,j:integer);
   begin
      first:=1;
      last:=0;
      put(i,j);
      while first<=last do begin
         get(i,j);
         put(i+1,j);
         put(i-1,j);
         put(i,j+1);
         put(i,j-1);
      end;
   end;

begin
   new(ii);
   new(jj);
   assign(input,'c:\beds.in');
   assign(output,'c:\beds.out');
   reset(input);
   rewrite(output);
   readln(input,n,m);
   for i:=0 to n+1 do
      for j:=0 to m+1 do
         c[i,j]:='.';
   for i:=1 to n do begin
      for j:=1 to m do
         read(input,c[i,j]);
      readln(input);
   end;
   count:=0;
   for i:=1 to n do
      for j:=1 to m do
         if c[i,j]='#' then begin
            paint(i,j);
            inc(count);
         end;
   write(output,count);
   close(input);
   close(output);
end.
 
Ответить с цитированием