AcWing 425. 明明的随机数
原题链接
简单
作者:
D.Russell
,
2024-11-25 13:08:19
,
所有人可见
,
阅读 12
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int q[N], n;
void quick_sort(int q[], int l, int r) {
if (l >= r) return;
int x = q[l + r >> 1], i = l - 1, j = r + 1;
while (i < j) {
do i ++; while (q[i] < x);
do j --; while (q[j] > x);
if (i < j) swap(q[i], q[j]);
}
quick_sort(q, l, j);
quick_sort(q, j + 1, r);
}
int main()
{
cin >> n;
for (int i = 0; i < n; i ++) cin >> q[i];
quick_sort(q, 0, n - 1);
int past = q[0], sum = 1;
for (int i = 1; i < n; i ++) {
if (q[i] != past) {
sum ++;
past = q[i];
}
}
cout << sum << endl << q[0] << ' ';
past = q[0];
for (int i = 1; i < n; i ++) {
if (q[i] != past) {
cout << q[i] << ' ';
past = q[i];
}
}
return 0;
}