比赛 20091110 评测结果 AAAAAAAAAA
题目名称 查字典 最终得分 100
用户昵称 lc 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-10 10:25:26
显示代码纯文本
program scanword;
 const
   maxn = 10000;
 type
   rtype = record
         s:     string;
         p:     longint;
         end;
 var
   n,m: longint;
   w:   array[1..maxn] of rtype;



procedure qsort(l,r:longint);
 var
   i,j: longint;
   x:   string;
   temp:rtype;
 begin
   i :=l; j :=r; x :=w[(i+j) shr 1].s;
   repeat
     while w[i].s <x do inc(i);
     while w[j].s >x do dec(j);
     if i <=j then begin
        temp :=w[i]; w[i] :=w[j]; w[j] :=temp;
        inc(i);  dec(j);
        end;
   until i >j;
   if j >l then qsort(l,j);
   if i <r then qsort(i,r);
 end;


procedure init;
 var
   i:   longint;
 begin
   readln(n);
   for i :=1 to n do begin
       readln(w[i].s);
       readln(w[i].p);
       end;
   qsort(1,n);
 end;


function find(s:string):longint;
 var
   l,r,mid:     longint;
 begin
   l :=1; r :=n;
   while true do begin
     mid :=(l+r) shr 1;
     if w[mid].s = s then exit(w[mid].p);
     if w[mid].s <s then l :=mid+1
                    else r :=mid-1;
     end;
 end;



procedure main;
 var
   i:   longint;
   s:   string;
 begin
   readln(m);
   for i :=1 to m do begin
       readln(s);
       writeln(find(s));
       end;
 end;



begin
  assign(input,'scanword.in');  reset(input);
  assign(output,'scanword.out'); rewrite(output);
  init;
  main;
  close(input);  close(output);
end.