比赛 20091110 评测结果 C
题目名称 查字典 最终得分 0
用户昵称 王瑞祥K 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-10 11:03:41
显示代码纯文本
program scanword(input,output);
const h=13999;
var
 word:string;
 page,i,n,m:longint;
 w:array[0..100000] of string;
 p:array[0..100000] of longint;
function hash(word:string):longint;
var i:longint;
begin
 hash:=ord(word[1])-96;
 for i:=2 to 3 do
  hash:=(hash*27+ord(word[i*2-1])-96) mod h;
end;
procedure makeh(word:string; page:longint);
var i,hc:longint;
begin
 hc:=hash(word);
 while w[hc]<>'' do hc:=(hc+1) mod h;
 w[hc]:=word;
 p[hc]:=page;
end;
function find(word:string):longint;
var hc:longint;
begin
 hc:=hash(word);
 while (w[hc]<>'')and(w[hc]<>word) do hc:=(hc+1) mod h;
 find:=p[hc];
end;
begin
 assign(input,'scanword.in');assign(output,'scanword.out');
 reset(input);rewrite(output);
 readln(n);
 for i:=1 to n do begin
  readln(word);
  readln(page);
  makeh(word,page);
 end;
 readln(m);
 for i:=1 to m do begin
  readln(word);
  writeln(find(word));
 end;
 close(input);close(output);
end.