题解 | Simple Sorting
Simple Sorting
https://www.nowcoder.com/practice/139761e0b59a405786898b7f2db9423f
#include <iostream>
#include <vector>
using namespace std;
int cmp(const void* a, const void* b) {
return (*(int*)a - * (int*)b);
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
qsort(a, n, sizeof(int), cmp);
int len = n;
for (int i = 0; i < len; i++) {
if (a[i] == a[i + 1]) {
for (int j = i + 1; j < len - 1; j++) {
a[j] = a[j + 1];
}
len--;
i--;
}
}
if (len < n) {
for (int i = 0; i <= len; i++) {
cout << a[i] << " ";
}
} else {
for (int i = 0; i < len; i++) {
cout << a[i] << " ";
}
}
}
// 64 位输出请用 printf("%lld")

查看9道真题和解析