那天考试看到了这题..于是就用最朴素的建树的方法爽爽地写了一通.
当然方法不止这么一种.还有好多比这个快的方法...但是我还是觉得没我这个写的爽...
顺便测试一下WP-Syntax.哈哈...题目和程序点进去看吧
【题目描述】
黑客Bill不小心丢失了他的工作站硬盘上的所有数据,而且没有备份。他没有因为丢失文件感到遗憾,倒是因为那些在工作多年中建立起来的非常便利好用的目录结构而感到遗憾。
幸运的是,他由几个目录表的备份。根据这些列表,他能恢复某些完整的路径 (譬如 "WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86")。他把这些信息全部写到一个文件中,请你帮忙恢复目录结构树。
【输入数据】
首行为整数N (1 ≤ N ≤ 500),表示目录路径数目。以下N行,每行为一个目录路径,不包含任何空格(包括前导空格或后置空格),都不超过80个字符,每个目录路径只出现一次,由一系列的目录名称组成,用"\"隔开。
每个目录由1到8个大写字母、数字或以下指定的字符组成:"!#$%&'()-@^_`{}~"。
【输出数据】
输出目录树。 每个目录名一行,前面由若干空格,表示它的目录深度,子目录必须按照字典序排列在父目录之后,之前有一个或多个空格。最顶级的目录名之前没有空格,同样也是按照字典序排。具体参看下例:
提供程序:
program disk; type treetype=^temptype; temptype=record data:string; son,bro:treetype; end; var root,null:treetype; n:longint; procedure tree_insert(var f,node:treetype); begin if node^.data=f^.son^.data then begin dispose(node); node:=f^.son; exit; end; if node^.data<f^.son^.data then begin node^.bro:=f^.son; f^.son:=node; exit; end; f:=f^.son; while node^.data>f^.bro^.data do f:=f^.bro; if f^.bro^.data=node^.data then begin dispose(node); node:=f^.bro; exit; end; node^.bro:=f^.bro; f^.bro:=node; end; procedure deal(s:string); var t:string; now,tmp:treetype; k:integer; begin now:=root; k:=pos(chr(92),s); while k>0 do begin t:=copy(s,1,k-1); tmp:=new(treetype); tmp^.data:=t; tmp^.son:=null; tmp^.bro:=null; tree_insert(now,tmp); now:=tmp; delete(s,1,k); k:=pos(chr(92),s); end; t:=s; tmp:=new(treetype); tmp^.data:=t; tmp^.son:=null; tmp^.bro:=null; tree_insert(now,tmp); now:=tmp; end; procedure init; var i:longint; t:string; begin root:=new(treetype); null:=new(treetype); root^.data:=''; null^.data:=chr(255); root^.son:=null; null^.son:=null; root^.bro:=null; null^.bro:=null; readln(n); for i:=1 to n do begin readln(t); deal(t); end; end; procedure print(now:treetype;deep:integer); var i:longint; begin if now=null then exit; for i:=1 to deep do begin write(' '); end; if deep<>-1 then writeln(now^.data); print(now^.son,deep+1); print(now^.bro,deep); end; begin assign(input,'disk.in'); reset(input); assign(output,'disk.out'); rewrite(output); init; print(root,-1); close(input); close(output); end.

咳..行号还是有点问题的说..
以及"\"竟然被...可悲的...算了.
为什么你的代码高亮这么奇怪呢。。。
不过还是很漂亮的说~
话说我还不大懂这题的树怎么写~