记录编号 11230 评测结果 AAAAAAAAAA
题目名称 [NOIP 2007]统计数字 最终得分 100
用户昵称 Gravatarmaxiem 是否通过 通过
代码语言 Pascal 运行时间 0.506 s
提交时间 2009-07-19 09:07:21 内存使用 0.26 MiB
显示代码纯文本
program pcount;
var
  tree:array [1..10000] of record
    sum,left,right,num:longint;
  end;
  i,now,l,last,tmp,n:longint;
  new:boolean;
procedure go(root:integer);
begin
  if root<>0 then begin
    go(tree[root].left);
    writeln (tree[root].num,' ',tree[root].sum);
    go(tree[root].right);
  end;
end;
begin
  fillchar (tree,sizeof(tree),0);
  assign (input,'pcount.in');
  reset (input);
  readln (n);
  assign (output,'pcount.out');
  rewrite (output);
  readln (tree[1].num);
  tree[1].sum:=1;last:=1;
  for i:=2 to n do begin
    readln (tmp);
    now:=1;new:=true;
    repeat
      if tmp=tree[now].num then begin
        inc(tree[now].sum);
        new:=false;break;
      end
      else begin
        l:=now;
        if tmp<tree[now].num then now:=tree[now].left else now:=tree[now].right;
      end;
    until now=0;
    if new then begin
      inc(last);
      if tmp<tree[l].num then tree[l].left:=last else tree[l].right:=last;
      tree[last].num:=tmp;
      tree[last].sum:=1;
    end;
  end;
  close (input);
  go(1);
  close (output);
end.