记录编号 15223 评测结果 AAAAAAAAAA
题目名称 查字典 最终得分 100
用户昵称 Gravatar麦、洛洛 是否通过 通过
代码语言 Pascal 运行时间 0.362 s
提交时间 2009-11-10 19:43:04 内存使用 5.03 MiB
显示代码纯文本
program cdc;
type    c=record
        s:string;
        r:integer;
end;
var
        f:text;
        x:array[1..10000] of c;
        b:array[1..10000] of string;
        a:array[1..10000] of integer;
        i,j,l,n,m,y1,y2,y3,U,t,db1,db2:integer;
        st,k:string;
        flg:boolean;
procedure kp(t,u:integer);
begin
        k:=x[(t+u)div 2].s;
        db1:=t;
        db2:=U;
        repeat
        while x[db1].s<k do inc(db1);
        while x[db2].s>k do dec(db2);
        if db1<=db2 then
                begin
                        st:=x[db1].s;
                        x[db1].s :=x[db2].s;
                        x[db2].s:=st;
                        l:=x[db1].r;
                        x[db1].r:=x[db2].r;
                        x[db2].r:=l;
                        inc(db1);
                        dec(db2);
                end;
        until db1>db2;
        if db1<u then kp(db1,U);
        if t<db2 then kp(t,db2);
end;
begin
        assign(f,'scanword.in');
        reset(f);
        readln(f,n);
        for i:=1to n do
        begin
                readln(f,x[i].s);
                readln(f,x[i].r);
        end;
        readln(f,m);
        for i:=1 to m do
        readln(f,b[i]);
        close(f);
        kp(1,n);
        for i:=1 to m do
        begin
                flg:=false;
                y1:=0;
                y2:=n;
                while not(flg) do
                begin
                        y3:=(y1+y2) div 2;
                        if x[y3].s<b[i] then
                        y1:=y3+1;
                        if x[y3].s>b[i] then
                        y2:=y3;
                        if x[y3].s=b[i] then
                        begin
                                a[i]:=x[y3].r;
                                flg:=true;
                        end;
                end;
        end;
        assign(f,'scanword.out');
        rewrite(f);
        for i:=1 to m do
        writeln(f,a[i]);
        close(f);
end.