比赛 20091110 评测结果 AAAAAAAAAA
题目名称 查字典 最终得分 100
用户昵称 打不死的羊 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-10 10:32:07
显示代码纯文本
program scanword;
type
fxz1=array[1..10000] of string;
fxz2=array[1..10000] of longint;
var
f1,f2:text;
i,j,m,n:longint;
s:string;
ss:fxz1;
num:fxz2;


     procedure qsort(left,right:longint);
     var
     l,r,ls:longint;
     x,y:string;
     begin
     l:=left; r:=right; x:=ss[(l+r) div 2];
     repeat
     while ss[l]<x do inc(l);
     while ss[r]>x do dec(r);
     if l<=r then
      begin
      y:=ss[l];
      ss[l]:=ss[r];
      ss[r]:=y;
      ls:=num[l];
      num[l]:=num[r];
      num[r]:=ls;
      inc(l); dec(r);
      end;
     until l>r;
     if l<right then qsort(l,right);
     if r>left then qsort(left,r);
     end;


      procedure sou(l,r:longint);
      var
      x:string;
      begin x:=ss[(l+r) div 2];
            if x=s then writeln(f2,num[(l+r) div 2])
                   else begin if x>s then sou(l,(l+r) div 2)
                                     else sou(((l+r) div 2)+1,r);
                        end;
      end;







begin assign(f1,'scanword.in');
      assign(f2,'scanword.out');
      reset(f1);rewrite(f2);
      readln(f1,n);
      for i:=1 to n do begin readln(f1,ss[i]);
                             readln(f1,num[i]);
                       end;
      qsort(1,n);
      readln(f1,m);
      for i:=1 to m do
      begin readln(f1,s);
            sou(1,n);
      end;
      close(f1);close(f2);
end.