type aa=record
shu:longint;
ji:integer;
end;
var
l:aa;
h:longint;
a:array[1..200000]of aa;
n,m,s:integer;
begin
fillchar(a,sizeof(a),0);
readln(n);
for s:=1 to n do
begin
readln (h);
for m:=1 to s do
if a[m].shu=h then a[m].ji:=a[m].ji+1;
if a[m].shu<>h then if a[m].shu=0 then
begin
a[m].shu:=h;
a[m].ji:=1;
end else ;
end;
for s:=1 to n-1 do
for m:=s+1 to n do
if a[s].shu>a[m].shu then
begin
l:=a[s];
a[s]:=a[m];
a[m]:=l;
end;
for s:=1 to n do
writeln(a[s].shu,' ',a[s].ji);
end.
帮忙看一下
不好看。。
其实就是个快排而已啊
var
a:array[1..200000] of longint;
c,b:array[1..11000] of longint;
num,i,j,n:longint;
procedure qsort(x,y:longint);
var
head,tail,k:longint;
begin
head:=x;tail:=y;k:=a[head];
while x<y do
begin
while (x<y)and(a[y]>=k) do y:=y-1;
a[x]:=a[y];
while (x<y)and(a[x]<=k) do x:=x+1;
a[y]:=a[x];
end;
a[x]:=k;
if tail>x+1 then qsort(x+1,tail);
if head<x-1 then qsort(head,x-1);
end;
begin
readln(n);
for i:=1 to n do
readln(a[i]);
qsort(1,n);
num:=1;b[num]:=1;c[num]:=a[1];
for i:=2 to n do
begin
if a[i]>c[num] then begin
num:=num+1;
b[num]:=1;
c[num]:=a[i];
end
else
if a[i]=c[num] then b[num]:=b[num]+1;
end;
for i:=1 to num do
writeln(c[i],' ',b[i]);
close(input);
end.
快排之后还要统计重复数字的个数,b[i]记录的是第i个数是啥,c[i]记录的是第i个数有几个。
当然你完全没必要这样写,反正都有序了,统计下重复数字个数嘛,你可以写的更简单
input,输入文件格式,平时的习惯,在线提交的时候不可以带,删掉就好。