如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。

URAL/1067

来自"NOCOW"

跳转到: 导航, 搜索

字符串处理的题目,先排一遍序,再地归去做

program cao;
const
  maxn=600;
 
var
  data:array[0..maxn] of string;
  blank:array[0..80] of string;
  a,b,c,d,e,f,g,h,i,j,k,l,n,m,p,q:longint;
 
procedure qsort(left,right:longint);
var
  i,j:longint;
  x:string;
begin
  i:=left;
  j:=right;
  x:=data[(i+j)shr 1];
  while i<j do
  begin
    while data[i]<x do inc(i);
    while data[j]>x do dec(j);
    if i<=j then
    begin
      data[0]:=data[i];
      data[i]:=data[j];
      data[j]:=data[0];
      inc(i);
      dec(j);
    end;
  end;
  if i<right then qsort(i,right);
  if j>left then qsort(left,j);
end;
 
procedure init;
begin
  readln(n);
  for i:=1 to n do
  begin
    readln(data[i]);
    for j:=1 to length(data[i]) do
      if data[i][j]=‘\’ then data[i][j]:=#1;
   data[i]:=#1+data[i]+#1;
 end;
 qsort(1,n);
 for i:=1 to 80 do
   blank[i]:=blank[i-1]+’ ‘;
end;
 
procedure main(st,depth,top,bot:longint);
var
 i,j:longint;
 x:string;
begin
 while top<=bot do
 begin
   j:=top;
   for i:=st to length(data[top]) do
     if data[top][i]=#1 then break;
   x:=copy(data[top],st,i-st);
   inc(top);
   if x=’‘ then continue;
   for top:=top to bot+1 do
     if (copy(data[top],st,i-st)<>x)or(data[top][st-1]<>#1)or(data[top][i]<>#1) then break;
   writeln(blank[depth],x);
   main(i+1,depth+1,j,top-1);
 end;
end;
 
begin
 init;
 main(2,0,1,n);
end.

http://www.withflying.com/?p=129

http://www.withflying.com

个人工具