讨论 / 统计数字 ??、怎么错了?
luyao777 2010-10-11 17:07:00
点我顶贴 收藏 删除
program ee;

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.

帮忙看一下

#1 407137009@2010-10-11 06:07:00
回复 删除
回复 楼主luyao777 的帖子

不好看。。

其实就是个快排而已啊

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.

#2 luyao777@2010-10-11 06:12:00
回复 删除
回复 沙发407137009 的帖子

c,b这两个数组干啥用的?

#3 luyao777@2010-10-11 06:12:00
回复 删除
回复 沙发407137009 的帖子

c,b这两个数组干啥用的?

#4 luyao777@2010-10-11 06:16:00
回复 删除
还有那个input 是怎么回事?、
#5 649273254@2010-10-11 17:02:00
回复 删除
回复 地板luyao777 的帖子

快排之后还要统计重复数字的个数,b[i]记录的是第i个数是啥,c[i]记录的是第i个数有几个。

当然你完全没必要这样写,反正都有序了,统计下重复数字个数嘛,你可以写的更简单

input,输入文件格式,平时的习惯,在线提交的时候不可以带,删掉就好。

#6 407137009@2010-10-11 17:07:00
回复 删除
LS是我回的,用错号了。。

RT

查看更多回复
提交回复