记录编号 15162 评测结果 AAAAAAAAAA
题目名称 查字典 最终得分 100
用户昵称 GravatarZhouZn1 是否通过 通过
代码语言 Pascal 运行时间 0.528 s
提交时间 2009-11-10 15:51:26 内存使用 7.51 MiB
显示代码纯文本
program scanword;
type
rec=record
        ss:string;
        num:longint;
        end;
var
        n,i,j,cost,m:longint;
        data,a:array[1..10000]of rec;
        want:array[1..10000]of string;
procedure init;
begin
        assign(input,'scanword.in');
        reset(input);
        assign(output,'scanword.out');
        rewrite(output);
        readln(n);
        for i:=1 to n do
        begin
                readln(a[i].ss);
                readln(a[i].num);
        end;
        readln(m);
        for i:=1 to m do readln(want[i]);
end;
procedure swap(var a,b:rec);
var
        t:rec;
begin
        t:=a;
        a:=b;
        b:=t;
end;
procedure down(x:longint);
var
        best:longint;
begin
        if x*2>cost then exit;
        best:=2*x;
        if x*2+1<=cost then
         if a[x*2+1].ss<a[best].ss then inc(best);
        if a[best].ss<a[x].ss then
        begin
                swap(a[best],a[x]);
                down(best);
        end;
end;
procedure sort;
var
        i:longint;
begin
        cost:=n;
        for i:=n div 2 downto 1 do down(i);
        i:=0;
        while cost>0 do
        begin
                inc(i);
                data[i]:=a[1];
                a[1]:=a[cost];
                dec(cost);
                down(1);
        end;

end;
procedure main;
var
        a1,a2,a3,i:longint;
        flg:boolean;
begin
        sort;
        for i:=1 to m do
        begin
                a1:=0;
                a2:=n;
                flg:=false;
                while not(flg) do
                begin
                        a3:=(a1+a2)shr 1;

                        if data[a3].ss>want[i] then
                        a2:=a3;
                        if data[a3].ss<want[i] then
                        a1:=a3+1;
                        if data[a3].ss=want[i] then
                        begin
                                writeln(data[a3].num);
                                flg:=true;
                                break;
                        end;
                end;
        end;
end;
procedure closef;
begin
        close(input);
        close(output);
end;
begin
        init;
        main;
        closef;
end.