|
|
back to boardHelp!!! Why I got 'wang answer'? Posted by qwt 28 Mar 2002 13:53 type ttype=^ntype; ntype=record f,t,v:longint; next:ttype; end; var a,la,lb,p,q:ttype; i,j,k,x,y,z,n,r:longint; begin read(n); la:=nil; lb:=nil; for i:=1 to n do begin new(p);read(x,y,z); if x>y then begin r:=x;x:=y;y:=r;end; p^.f:=x;p^.t:=y;p^.v:=z;p^.next:=nil; if la=nil then la:=p else begin q:=la; if q^.f>p^.f then begin p^.next:=q; la:=p; end else begin while q^.next<>nil do begin if q^.next^.f>p^.f then break; q:=q^.next; end; p^.next:=q^.next; q^.next:=p; end; end; end; readln; read(n); for i:=1 to n do begin new(p);read(x,y,z); if x>y then begin r:=x;x:=y;y:=r;end; p^.f:=x;p^.t:=y;p^.v:=z;p^.next:=nil; if lb=nil then lb:=p else begin q:=lb; if q^.f>p^.f then begin p^.next:=q; lb:=p; end else begin while q^.next<>nil do begin if q^.next^.f>p^.f then break; q:=q^.next; end; p^.next:=q^.next; q^.next:=p; end; end; end; a:=la; while (lb<>nil)and(a<>nil) do begin while (lb<>nil)and(lb^.t<a^.f) do lb:=lb^.next; if lb=nil then break; while (a<>nil)and(a^.t<lb^.f) do a:=a^.next; if a=nil then break; if lb^.f<=a^.f then begin if lb^.t>=a^.t then begin a^.t:=a^.f; a:=a^.next; end else begin a^.f:=lb^.t; lb:=lb^.next; end; end else begin if lb^.t>=a^.t then begin a^.t:=lb^.f; lb:=lb^.next; end else begin new(q); q^.f:=lb^.t; q^.t:=a^.t; q^.v:=a^.v; a^.t:=lb^.f; q^.next:=a^.next; a^.next:=q; lb:=lb^.next; end; end; end; a:=la; i:=0; while a<>nil do begin if a^.t>a^.f then inc(i); a:=a^.next; end; write(i,' '); while la<>nil do begin if la^.t>la^.f then write(la^.f,' ',la^.t,' ',la^.v,' '); la:=la^.next; end; writeln; end. |
|
|