Pascal数的统计
发布网友
发布时间:2024-10-23 22:45
我来回答
共1个回答
热心网友
时间:2024-10-31 05:07
var i,s,n:longint;
a:array[1..200000] of longint;
procedure s1(l,r:longint);
var t,mid,i,j:longint;
begin
i:=l;j:=r;
mid:=a[(i+j) div 2];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then
begin t:=a[i];a[i]:=a[j];a[j]:=t;inc(i);dec(j);end;
until i>j;
if l<j then s1(l,j);
if i<r then s1(i,r);
end;
begin
assign(input,'count.in');reset(input);
assign(output,'count.out');rewrite(output);
read(n);for i:=1 to n do read(a[i]);
s1(1,n);
s:=1;
for i:=2 to n do
if a[i]=a[i-1] then inc(s)
else begin writeln(a[i-1],' ',s); s:=1; end;
write(a[n],' ',s);
close(input);close(output);
end.