Thứ Ba, 3 tháng 5, 2022

ITABLE Pascal

var a:array[0..1005,0..1005] of char;
        b:array[0..1005,0..1005] of longint;
        c:array[1..1000000] of char;
        m,n,x,y,i,j,k,d,res:longint;
procedure nhap;
begin
        readln(m,n);
        for i:=1 to m do
        begin
                for j:=1 to n do read(a[i,j]);
                readln;
        end;
end;
procedure tao_vien;
begin                                                    
        for i:=0 to m+1 do
        begin
                b[i,0]:=3;
                b[i,n+1]:=3;
        end;
        for i:=0 to n+1 do
        begin
                b[0,i]:=3;
                b[m+1,i]:=3;
        end;
end;
procedure truyvet(x,y,k:longint);
begin
        for i:=d downto 1 do
        begin
                if c[i]='W' then inc(y)
                else if c[i]='E' then dec(y)
                else if c[i]='S' then dec(x)
                else if c[i]='N' then inc(x);
                b[x,y]:=k;
        end;
end;
procedure di(x,y:longint);
begin
        d:=0;
        repeat
                inc(d);c[d]:=a[x,y]; b[x,y]:=1;
                if a[x,y]='W' then dec(y)
                else if a[x,y]='E' then inc(y)
                else if a[x,y]='N' then dec(x)
                else if a[x,y]='S' then inc(x)
        until b[x,y]<>0;
        if (b[x,y]=3) or (b[x,y]=2) then truyvet(x,y,2) ;
       // else
             //   if b[x,y]=1 then truyvet(x,y,1);
end;
procedure xuatbang;
var i,j:longint;
begin

        for i:=0 to m+1 do
        begin
                for j:=0 to n+1 do write(b[i,j],' ');
                writeln;
        end;
end;
procedure giai;
begin
        for i:=1 to m do
                for j:=1 to n do
                        if b[i,j]=0 then
                        begin
                           //     writeln(i,' ',j);
                                di(i,j);
                             //   xuatbang;
                             //   writeln;
                        end;
        res:=0;
        for i:=1 to m do
                for j:=1 to n do
                        if b[i,j]=1 then inc(res);
        writeln(res);

end;
begin
        assign(input,'itable.inp');reset(input);
        assign(output,'itable.out');rewrite(output);
        nhap;
        tao_vien;
        giai;

end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.