记录编号 15227 评测结果 AAAAAAAAAA
题目名称 查字典 最终得分 100
用户昵称 Gravatarmaxiem 是否通过 通过
代码语言 Pascal 运行时间 0.275 s
提交时间 2009-11-10 21:22:03 内存使用 1.18 MiB
显示代码纯文本
program scanword;
var
  tree:array [1..10000] of record
    left,right:integer;
    s:string[100];
    p:longint;
  end;
  tmp:string;
  top,i,n,m:integer;
  page:longint;
procedure find(root:integer);
begin
  if root<>0 then begin
    if tree[root].s=tmp then writeln(tree[root].p)
    else begin
      if tmp<tree[root].s then find(tree[root].left);
      if tmp>tree[root].s then find(tree[root].right);
    end;
  end;
end;
procedure build(root:integer);
begin
  if tmp<tree[root].s then begin
    if tree[root].left=0 then begin
      inc(top);
      tree[root].left:=top;
      tree[top].s:=tmp;
      tree[top].p:=page;
    end
    else build (tree[root].left);
  end
  else begin
    if tree[root].right=0 then begin
      inc(top);
      tree[root].right:=top;
      tree[top].s:=tmp;
      tree[top].p:=page;
    end
    else build(tree[root].right);
  end;
end;
begin
  assign (input,'scanword.in');
  reset (input);
  assign (output,'scanword.out');
  rewrite (output);
  readln (n);
  for i:=1 to n do begin
    tree[i].left:=0;
    tree[i].right:=0;
    tree[i].s:='';
    tree[i].p:=0;
  end;
  top:=1;
  readln (tree[1].s);
  readln (tree[1].p);
  for i:=2 to n do begin
    readln (tmp);
    readln (page);
    build(1);
  end;
  readln (m);
  for i:=1 to m do begin
    readln (tmp);
    find(1);
  end;
  close (input);
  close (output);
end.