讨论 / 错在哪?
wuzw 2011-10-26 17:57:00
点我顶贴 收藏 删除
type r=^shu;

shu=record

x:array[0..1000]of integer;

end;

const

a='a';b='b';c='c';d='d';

var s,s1,s2:r;

n,t1,i,m,t2,li:integer;

l:array[1..2000]of char;bl:boolean;

procedure work(var i:integer;si:r;var ti:integer;xj,yj:char);

begin

repeat if si^.x[ti]=m then//

begin

inc(li);l[li]:=yj;dec(ti);inc(m);

end;

until si^.x[ti]<>m;

if i>n then exit;

if (s^.x[i]<si^.x[ti])and(ti>=0) then //

begin

inc(ti);si^.x[ti]:=s^.x[i];inc(li);l[li]:=xj;

repeat if si^.x[ti]=m then//

begin

inc(li);l[li]:=yj;dec(ti);inc(m);

end;

until si^.x[ti]<>m;

end

else

if (s^.x[i]<s2^.x[t2])or(s2^.x[t2]=m) then work(i,s2,t2,c,d)

else begin writeln('0');halt;end;

inc(i);

work(i,s1,t1,a,b);work(i,s2,t2,c,d);

end;

begin

new(s);new(s1);new(s2);

m:=1;

s1^.x[0]:=maxint; s2^.x[0]:=maxint;

readln(n);

for i:=1 to n do read(s^.x[i]);

i:=1;

work(i,s1,t1,a,b);

for i:=1 to n+n-2 do write(l[i],' ');//

if l[n+n-1]<>'' then write(l[n+n-1],' ') else write('d',' ');//

writeln(l[n+n]);

readln ;readln

end.

查看更多回复
提交回复