-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeat_element.cpp
More file actions
45 lines (44 loc) · 1020 Bytes
/
repeat_element.cpp
File metadata and controls
45 lines (44 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
using namespace std;
int comp(const void *a, const void *b)
{
return *((int *)a) - *((int *)b);
}
int main()
{
#ifdef LOCAL_JUDGE
freopen("input.txt", "rt", stdin);
#endif
int n;
int a[100];
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
qsort(a, n, sizeof(int), comp);
int cnt = 0;
for (int i = 1; i < n; i++) { //去重
if (a[i] == a[i - 1]) {
a[i - 1] = -1;
cnt++; //计数
}
}
printf("%d\n", n - cnt);
int first = 1;
for (int i = 0; i < n; i++)
if (a[i] != -1) {
if (first) {
first = 0;
printf("%d", a[i]);
} else
printf(" %d", a[i]);
}
printf("\n");
}
return 0;
}