比赛 20111110 评测结果 AAAAAAAAAA
题目名称 韩国明星 最终得分 100
用户昵称 reamb 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-11-10 11:22:01
显示代码纯文本
program start;
var
  a:array[1..100000]of string;
  b:array[1..100000]of longint;
  n,i,j,weizhi,k,d:longint;
  s:string;
procedure sort(l,r: longint);
      var
         i,j: longint;
         x,y:string;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
procedure sort2(l,r: longint);
      var
         i,j,x,y: longint;
         z:string;
      begin
         i:=l;
         j:=r;
         x:=b[(l+r) div 2];
         z:=a[(l+r) div 2];
         repeat
           while (b[i]>x)or((b[i]=x)and(a[i]<z)) do
            inc(i);
           while (x>b[j])or((b[j]=x)and(a[j]>z)) do
            dec(j);
           if not(i>j) then
             begin

                  y:=b[i];
                  b[i]:=b[j];
                  b[j]:=y;
                  z:=a[i];
                  a[i]:=a[j];
                  a[j]:=z;
                  inc(i);
                  j:=j-1;
             end;
         until i>j;
         if l<j then
           sort2(l,j);
         if i<r then
           sort2(i,r);
      end;
procedure find(x,y:longint);
var
  mid:longint;
begin
  mid:=(x+y)div 2;
  if x=y then
  begin
    weizhi:=x;
    exit
  end;
  if s<=a[mid] then
    find(x,mid)
  else
    find(mid+1,y)
end;
begin
  assign (input,'star.in');
  reset(input);
  assign (output,'star.out');
  rewrite (output);
    readln (n);
    for i:=1 to n do
      readln (a[i]);
    sort(1,n);
    readln (k);
    for i:=1 to k do
    begin
      readln (s);
      find(1,n);
      readln (d);
      inc(b[weizhi],d)
    end;
    sort2(1,n);
    for i:=1 to n do
    begin
      writeln (a[i]);
      writeln (b[i])
    end;
  close (input);
  close (output)
end.