-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1059.cpp
62 lines (54 loc) · 1.16 KB
/
P1059.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
using namespace std;
int main()
{
int count;
cin >> count;
int numbers[count];
for (int i = 0; i < count; i++)
{
cin >> numbers[i];
}
// 第一步:去重
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
if (i != j && numbers[i] == numbers[j] && numbers[i] != -1)
{
// 重复的值标为-1
numbers[j] = -1;
}
}
}
// 第二步:排序(冒泡)
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
if (i != j && numbers[i] < numbers[j])
{
int tmp = numbers[j];
numbers[j] = numbers[i];
numbers[i] = tmp;
}
}
}
// 第三步:输出结果
int total = 0;
for (int i = 0; i < count; i++)
{
if (numbers[i] != -1)
{
total += 1;
}
}
cout << total << endl;
for (int i = 0; i < count; i++)
{
if (numbers[i] != -1)
cout << numbers[i] << " ";
}
cout << endl;
return 0;
}