比赛 20090923练习赛 评测结果 WWWWWWWWWA
题目名称 背诵单词 最终得分 10
用户昵称 .Xmz 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-09-23 21:46:03
显示代码纯文本
program xmz;
var
 x:array[0..100]of string;
 y:array[0..100]of integer;
 n,a,b,maxx,maxi,s:integer;
 ss:char;
 t:string;
 f1,f2:text;
 f:array[0..100,0..100]of integer;
 z:array[0..100]of boolean;
 procedure zhi;
 var
 i:integer;
 begin
  i:=0;
  while (i<=19)and(x[a][i+1]=x[b][i+1]) do
  begin
  inc(i);
  end;
  f[a,b]:=i;
 end;

 procedure zhao(nn:integer);
  var i,min:integer;
  begin
   for i:=1 to n do
   if (i<>y[nn-1])and(not z[i]) then
   if f[y[nn-1],i]<min then begin min:=f[y[nn-1],i];y[nn]:=i;end;
   writeln(f2,x[y[nn]]);z[y[nn]]:=true;
  end;

 function da(xx,yy:integer):boolean;
  var i:integer;
  begin
   i:=0;
   if length(x[xx])>length(x[yy]) then da:=false
    else if length(x[xx])<length(x[yy]) then da:=true
     else
      begin
       repeat
        i:=i+1;
       until (x[xx][i]<>x[yy][i])or(i=length(x[xx]));
       if x[xx][i]>=x[yy][i] then da:=false;
       if x[xx][i]<x[yy][i] then da:=true;

      end;
  end;
begin
 assign(f1,'letter.in');assign(f2,'letter.out');
 reset(f1);rewrite(f2);
  readln(f1,n);
  for a:=1 to n do
   readln(f1,x[a]);
    for a:=0 to n do for b:=0 to n do if a<>b then     zhi;
  x[0][1]:='z';

  for a:=1 to n do
   begin
   for b:=1 to n do
    if not z[b] then if x[b][1]<=x[s][1] then begin s:=b;ss:=x[s][1];end;
   for b:=1 to n do
   if not z[b] then if f[a-1,b]>=maxi then begin maxi:=f[a-1,b];maxx:=b;end;
   if maxi=0 then begin maxx:=s;maxi:=1;
      for b:=1 to n do
   if not z[b] then if f[maxx,b]>=1 then if da(b,maxx) then maxx:=b;
   end;
   for b:=1 to n do
   if not z[b] then if (f[a-1,b]=maxi) then if da(b,maxx) then maxx:=b;
   y[a]:=maxx;maxi:=0;z[maxx]:=true;maxx:=0; s:=0;
   end;


  for a:=1 to n do
  writeln(f2,x[y[a]]);
 close(f1);close(f2);
end.