作业帮 > 综合 > 作业

pascal:数据统计

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 23:30:04
pascal:数据统计
有n个自然数属于【1,2000000000】
现在统计这些自然数出现的次数,并按自然数从小到大输出统计结果
例 输入8
2 4 2 4 5 100 2 100
输出 2 3
4 2
5 1
100 2
这是noip的一道水题,用快排就可以了,代码如下:
program tongjishuzi;
var a:array[1..200000]of int64;
t,n:longint;
procedure qsort(l,r:longint);
var t,m,n:longint;
k,c:int64;
begin
m:=l;
n:=r;
k:=a[(l+r)div 2];
repeat
while a[m]k do dec(n);
if mn;
if ml then qsort(l,n);
end;
procedure output;
var t:longint;
j,k:int64;
begin
k:=a[1];
j:=0;
for t:=1 to n do
if a[t]=k then inc(j)
else
begin
writeln(k,' ',j);
k:=a[t];
j:=1;
end;
writeln(k,' ',j);
end;
begin
readln(n);
for t:=1 to n do
read(a[t]);
qsort(1,n);
output;
end.