- FBI树
- 2009-07-31 21:25:24 @
为什么我的程序只有80分啊?
type
rec=record
left,right:longint;
data:char;
end;
var
a:array[1..1100]of rec;
n:longint;
s:string;
t:longint;
procedure create(k:string);
var
if0,if1:boolean;
i:longint;
left,right:string;
num:longint;
begin
num:=t;
if length(k)=1 then
begin
a[t].left:=0;
a[t].right:=0;
if k='1' then a[t].data:='I' else a[t].data:='B';
exit;
end;
if0:=false;
if1:=false;
for i:=1 to length(k) do
begin
if k[i]='0'then if0:=true;
if k[i]='1'then if1:=true;
end;
if (if0)and(if1)then a[t].data:='F';
if (if1)and(not if0) then a[t].data:='I';
if (if0)and(not if1) then a[t].data:='B';
left:=copy(k,1,length(k) div 2);
right:=copy(k,length(k) div 2+1,length(k)-(length(k) div 2));
t:=num*2;
a[num].left:=t;
create(left);
t:=num*2+1;
a[num].right:=t;
create(right);
end;
procedure work(i:longint);
begin
if (a[i].left=0)and(a[i].right=0)then
begin write(a[i].data);exit;end;
if a[i].left0 then work(a[i].left);
if a[i].right0 then work(a[i].right);
write(a[i].data);
end;
begin
readln(n);
readln(s);
t:=1;
create(s);
work(1);
writeln;
end.
4 条评论
-
唐思远 LV 8 @ 2017-07-02 17:44:27
把‘string'改成'ansistring',其他不变。
-
2015-07-17 21:03:23@
得用ansistring 才行
-
2013-10-19 14:58:01@
我也是,第一和最后一个点“Wrong Answer”
-
2013-04-01 19:05:15@
ME TOO
- 1