SSL
洛谷 P1059 明明的随机数
题目描述
明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作。
分析
辣么容易的题目。
快排(详情请看【模板】快速排序)玩以后,输出时在前面搞个循环去重。
这有什么难的????
var
n:longint;
a:array[1..101]of longint;
procedure init;
var
i:longint;
begin
readln(n);
for i:=1 to n do
read(a[i]);
end;
procedure quicksort(low,high:longint);
var
i,j,mid,temp:longint;
begin
i:=low;j:=high;mid:=a[(low+high)div 2];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then
begin
temp:=a[i];a[i]:=a[j];a[j]:=temp;
inc(i);dec(j);
end;
until i>j;
if i<high then quicksort(i,high);
if low<j then quicksort(low,j);
end;
procedure print;
var
i,s:longint;
begin
s:=0;
for i:=1 to n do if a[i]<>a[i+1] then inc(s);
writeln(s);
for i:=1 to n do if a[i]<>a[i+1] then write(a[i],' ');
end;
begin
init;
quicksort(1,n);
print;
end.
403

被折叠的 条评论
为什么被折叠?



