-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (45 loc) · 1.02 KB
/
Copy pathmain.cpp
File metadata and controls
63 lines (45 loc) · 1.02 KB
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
#include <iostream>
#include <vector>
#include <fstream>
std::vector<int> load(std::istream& input) {
std::vector<int> v;
int value;
while(input >> value)
v.push_back(value);
return v;
}
void store(const std::vector<int>& v , std::ostream& output) {
for (int value : v)
output << value << " ";
}
std::vector<int> drop_duplicates(const std::vector<int>& v) {
unsigned n = v.size();
std::vector<int> result;
for (int i = 0; i < n; i++) {
bool add = true;
for (int j = 0; j < i; j++) {
if (v[i] == v[j]) {
add = false;
break;
}
}
if (add)
result.push_back(v[i]);
}
return result;
}
unsigned nduplicates(const std::vector<int>& v) {
auto v_unq = drop_duplicates(v);
return v.size() - v_unq.size();
}
int main () {
//auto v = load(std::cin);
std::ifstream input("input.txt");
auto v = load(input);
std::cout << nduplicates(v) << std::endl;
v = drop_duplicates(v);
std::ofstream output("output.txt");
store(v,output);
// samom sam dodao prazan komentar u mainu
return 0;
}