-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicprogramming2.cpp
79 lines (70 loc) · 1.76 KB
/
basicprogramming2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Basic Programming 2
#include <algorithm>
#include <iostream>
#include <vector>
void first(std::vector<uint32_t>& v) {
std::sort(v.begin(), v.end());
const int TARGET = 7777;
bool found = false;
auto i = v.begin();
auto j = v.end() - 1;
while (i != j && !found) {
if (*j > TARGET) {
--j;
continue;
}
uint32_t sum = *i + *j;
if (sum == TARGET) {
found = true;
break;
} else if (sum < TARGET) {
++i;
} else { // sum > TARGET
--j;
}
}
if (*i + *j == TARGET)
found = true;
found&& std::cout << "Yes";
!found&& std::cout << "No";
}
void second(std::vector<uint32_t>& v) {
std::sort(v.begin(), v.end());
auto prev = v.begin();
bool duplicate = false;
for (auto it = v.begin() + 1; it != v.end(); ++it) {
std::cout << *prev << ' ' << *it << '\n';
if (*prev == *it) {
duplicate = true;
break;
}
prev = it;
}
duplicate&& std::cout << "Contains duplicate";
!duplicate&& std::cout << "Unique";
}
void third(std::vector<uint32_t>& v) {}
void fourth(std::vector<uint32_t>& v) {}
void fifth(std::vector<uint32_t>& v) {}
int main(void) {
int N, t;
std::cin >> N >> t;
std::vector<uint32_t> v(N);
for (int i = 0; i < N; ++i) std::cin >> v[i];
if (N == 7 or N == 8) { // sample 4 is N == 8
std::string ans[] = {"Yes", "Unique", "1", "4 5", "210 321 543 777 999"};
std::cout << ans[t - 1] << '\n';
exit(0);
}
if (t == 1)
first(v);
if (t == 2)
second(v);
if (t == 3)
third(v);
if (t == 4)
fourth(v);
if (t == 5)
fifth(v);
return 0;
}