PersonalCorpus 版 (精华区)

寄信人: sino (蚱蜢舟)
标  题: 1008
发信站: 哈工大紫丁香 (2002年03月22日05:56:21 星期五)
来  源: mtlab4.hit.edu.cn 

170016 21:58:14 21 Mar 2002
Bozhang,HIT,P.R.China 1008 Pascal Accepted 0.01 sec 53K 


const p:array [1..4,1..2] of integer=((1,0),(0,1),(-1,0),(0,-1));
      names:array [1..4] of char=('R','T','L','B');
var
    map:array[0..11,0..11] of boolean;
    path:array[1..100,1..2] of byte;
    ch:char;
    i,j,k,m,n:integer;
begin
    fillchar(map,sizeof(map),0);
    read(m);
    if eoln(input) then begin
        readln(path[1,1],path[1,2]);
        while m>1 do begin
            dec(m);
            readln(i,j);
            map[i,j]:=true;
        end;
        writeln(path[1,1],' ',path[1,2]);
        j:=1; k:=1;
        while j<=k do begin
            for i:=1 to 4 do begin
                inc(k);
                path[k,1]:=path[j,1]+p[i,1];
                path[k,2]:=path[j,2]+p[i,2];
                if map[path[k,1],path[k,2]] then begin
                    write(names[i]);
                    map[path[k,1],path[k,2]]:=false;
                end else dec(k);
            end;
            inc(j);
            if j<=k then writeln(',') else writeln('.');
        end;
    end else begin
        readln(n);
        path[1,1]:=m; path[1,2]:=n;
        j:=1;k:=1;
        while not eof(input) do begin
            while eoln(input) and not eof(input) do readln;
            if eof(input) then break;
            read(ch);
            while(ch<>',') and (ch<>'.') do begin
                for i:=1 to 4 do if ch=names[i] then begin
                    inc(k);
                    path[k,1]:=path[j,1]+p[i,1];
                    path[k,2]:=path[j,2]+p[i,2];
                end;
                read(ch);
            end;
            inc(j);
        end;
        for i:=1 to k-1 do begin
            m:=i;
            for j:=i+1 to k do if (path[m,1]>path[j,1]) or ((path[m,1]=path[
j,1]) and (path[m,2]>path[j,2])) then m:=j;
            if m<>i then begin
                j:=path[m,1]; path[m,1]:=path[i,1]; path[i,1]:=j;
                j:=path[m,2]; path[m,2]:=path[i,2]; path[i,2]:=j;
            end;
        end;
        writeln(k);
        for i:=1 to k do writeln(path[i,1],' ',path[i,2]);
    end;
end.
--
    我一直认为马佩军是西电编程第一高手,他编程的时候根本不是人,是指针。

                                             --《阳光男孩之大学十年》

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: mtlab4.hit.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.206毫秒