一道PASCAL题目

明明的随机数.
2025-01-05 16:47:37
推荐回答(2个)
回答(1):

program sd;
var n,i,j,s,t:longint;
a:array[1..10000] of longint;
begin
read(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if a[i]>a[j] then begin t:=a[i];a[i]:=a[j];a[j]:=t;end;
if a[i]=a[j] then a[i]:=0;
end;
for i:=1 to n do
if a[i]<>0 then s:=s+1;
writeln(s);
for i:=1 to n do
if a[i]<>0 then write(a[i],' ');
end.

回答(2):

var
a:array[1..1000] of integer;
i,j:longint;
b,n:integer;
begin
for i:=1 to 1000 do
a[i]:=0;
begin
readln(n);
for i:=1 to n do
begin
read(b);
a[b]:=a[b]+1;
end;
for i:=1 to 1000 do
if a[i]>=1 then inc(j);
writeln(j);
for i:=1 to 1000 do
if a[i]>=1 then write(i,' ');
end;
end.