codeves天梯 明明的随机数
来源:互联网 发布:为什么知乎回答很慢 编辑:程序博客网 时间:2024/05/20 06:55
明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作。
分析
数据很小,直接暴力排序加判断。
const
maxn=1000000;var
a:array [1..maxn] of longint;
flag:array [1..maxn] of boolean;
i,n,ans:longint;
procedure init;
var
i:longint;
begin
readln(n);
for i:=1 to n do
read(a[i]);
ans:=n;
end;
procedure qsort(l,r:longint);
var
i,j,k,mid:longint;
begin
i:=l;j:=r;mid:=a[(l+r) div 2];
repeat
while a[i]<mid do
inc(i);
while a[j]>mid do
dec(j);
if i<=j then
begin
k:=a[i];
a[i]:=a[j];
a[j]:=k;
inc(i);dec(j);
end;
until i>j;
if i<r then
qsort(i,r);
if j>l then
qsort(l,j);
end;
procedure main;
var
i:longint;
begin
qsort(1,n);
for i:=1 to n do
if flag[a[i]] then
begin
dec(ans);
a[i]:=0;
end
else
flag[a[i]]:=true;
writeln(ans);
for i:=1 to n do
if a[i]<>0 then
write(a[i],' ');
end;
begin
init;
main;
end.
0 0
- codeves天梯 明明的随机数
- codeves天梯 明明的随机数
- 天梯-明明的随机数
- codevs 天梯 明明的随机数
- Wikioi 天梯 明明的随机数(1075)
- wikioi天梯之1075 明明的随机数
- codeves天梯 不高兴的津津
- codeves天梯 数的计算
- codeves天梯 校门口的数
- codeves天梯 开心的金明
- codeves天梯 津津的储蓄计划
- codeves天梯 均分纸牌
- codeves天梯 采药
- codeves天梯 Cantor表
- codeves天梯 火星人
- codeves天梯 FBI树
- codeves天梯 花生采摘
- codeves天梯 麦森数
- [机器学习]二分k-means算法详解
- HDU-1576 A/B
- 300. Longest Increasing Subsequence -Medium
- android中selector的用法
- Atitit java读取tif文件为空null的解决 图像处理
- codeves天梯 明明的随机数
- linux
- python抽象-类
- 博客第一天
- Atitit codeblock c++开发环境建立attilax总结
- SpringBoot集成MyBatis
- Atitit 摄像头与主机连接方式大总结
- servlet单实例多线程模式
- K短路新姿势