-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path2019_K1_1.c
70 lines (60 loc) · 1.46 KB
/
2019_K1_1.c
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
63
64
65
66
67
68
69
70
#include <stdio.h>
#define N_MAX 1000
int main(void)
{
while (1) {
int n;
scanf("%u", &n);
if (n < 3) break;
unsigned array[N_MAX];
for (int i = 0; i < n; i++) {
scanf("%u", &array[i]);
}
for (int i = 0; i < n; i++) {
printf("%u ", array[i]);
}
putchar('\n');
for (int i = 0; i < n; i++) {
int removed = 0;
for (int j = i+1, k = j; j < n; j++) {
if (array[i] != array[j]) {
array[k++] = array[j];
} else {
removed++;
}
}
n -= removed;
}
for (int i = 0; i < n; i++) {
printf("%u ", array[i]);
}
putchar('\n');
unsigned max[] = {0, 0, 0};
for (int i = 0; i < n; i++) {
if (array[i] > max[0]) {
max[2] = max[1];
max[1] = max[0];
max[0] = array[i];
} else if (array[i] > max[1]) {
max[2] = max[1];
max[1] = array[i];
} else if (array[i] > max[2]) {
max[2] = array[i];
}
}
for (int i = 0; i < 3; i++) {
if (n > i) {
printf("%u\n", max[i]);
} else {
puts("x");
}
}
}
return 0;
}
// Test:
// 11
// 1 10 1 2 2 5 6 7 8 7 7
// 5
// 1 1 1 1 1
// 0