forked from SarahN18/Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
46 lines (42 loc) · 857 Bytes
/
vector.cpp
File metadata and controls
46 lines (42 loc) · 857 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
46
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v(n);
for (auto &e : v)
{
cin >> e;
}
vector<int> w;
// int min = *min_element(v.begin(),v.end());
for (int i = 0; i < n; i++)
{
w.push_back(v[i]);
}
sort(v.begin(), v.end());
// loop through vector w and search for vector v elements , if they match delete that element from vector w
int j = 0;
for (int i = 0; i < w.size(); i++)
{
if (v[j] == w[i])
{
w.erase(w.begin() + i);
j++;
i--;
}
}
for (int i = 0; i < w.size(); i++)
{
cout << w[i] << " ";
}
cout << endl;
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << " ";
}
}