比赛 暑假培训六 评测结果 AAAEEEEEEA
题目名称 统计数字 最终得分 40
用户昵称 Oo湼鞶oO 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-23 11:21:14
显示代码纯文本
{*******************************************}
{* Program Name: pcount                    *}
{* Input File: pcount.in                   *}
{* Output File: pcount.out                 *}
{* Date: 2008.7.23                         *}
{* Programmer: Peng Bo                     *}
{*******************************************}
program pcount;
type
  jl=record
    c:word;
    s:longint;
    end;
  sz=array[1..1000]of jl;
var
  s:sz;
  n:longint;
  m:word;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure pc(t:longint);
var
  f:boolean;
  i:word;
begin
  f:=true;
  for i:=1 to m do
    if s[i].s=t
    then
    begin
      inc(s[i].c);
      f:=false;
      break;
    end;
  if f
  then
  begin
    inc(m);
    s[m].s:=t;
    s[m].c:=1;
  end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure input;
var
  f:text;
  i:word;
  t:longint;
begin
  assign(f,'pcount.in');
  reset(f);
  readln(f,n);
  for i:=1 to n do
  begin
    readln(f,t);
    pc(t);
  end;
  close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure output;
var
  f:text;
  i:word;
begin
  assign(f,'pcount.out');
  rewrite(f);
  for i:=1 to m do
    writeln(f,s[i].s,' ',s[i].c);
  close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure px(l,r:word);
var
  i,j:word;
  x:longint;
  t:jl;
begin
  i:=l;
  j:=r;
  x:=s[(l+r)div 2].s;
  repeat
    while s[i].s<x do
      inc(i);
    while x<s[j].s do
      dec(j);
    if i<=j
    then
    begin
      t:=s[i];
      s[i]:=s[j];
      s[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j
  then
    px(l,j);
  if i<r
  then
    px(i,r);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
  m:=0;
  input;
  px(1,m);
  output;
end.