记录编号 15495 评测结果 AAAAAAAAAA
题目名称 查字典 最终得分 100
用户昵称 Gravatarreamb 是否通过 通过
代码语言 Pascal 运行时间 0.370 s
提交时间 2009-11-13 15:21:34 内存使用 1.11 MiB
显示代码纯文本
program erfenchazhao;
var
  n,k,jilu,l:longint;
  m:string;
  a:array[1..10000]of string [100];
  b:array[1..10000]of longint;
procedure qsort(l,r: longint);
  var
    i,j,y1: longint;
    x,y2:string;
  begin
    i:=l;j:=r; x:=a[(l+r) div 2];
    repeat
      while a[i]<x do  inc(i);
      while x<a[j] do  dec(j);
      if i<=j then
      begin
        y2:=a[i];
        a[i]:=a[j];
        a[j]:=y2;
        y1:=b[i];
        b[i]:=b[j];
        b[j]:=y1;
        inc(i);
        dec(j);
     end;
     until i>j;
     if l<j then qsort(l,j);
     if i<r then qsort(i,r);
  end;
procedure chazhao(x1,y1:integer);
begin
  if a[(x1+y1) div 2]=m then
  begin
    jilu:=(x1+y1) div 2;
    exit
  end;
  if a[(x1+y1) div 2]>m then
  begin
    chazhao(x1,(x1+y1) div 2-1);
    exit
  end
  else
  begin
    chazhao((x1+y1) div 2+1,y1);
    exit
  end
end;
begin
  assign (input,'scanword.in');
  reset (input);
  assign (output,'scanword.out');
  rewrite (output);
  readln (n);
  for k:=1 to n do
  begin
    readln (a[k]);
    readln (b[k]);
  end;
  qsort (1,n);
  readln (l);
  for k:=1 to l do
  begin
    readln (m);
    chazhao(1,n);
    writeln (b[jilu])
  end;
  close (input);
  close (output)
end.