-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector-set.cpp
More file actions
54 lines (35 loc) · 1.14 KB
/
vector-set.cpp
File metadata and controls
54 lines (35 loc) · 1.14 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
//Napisz program który pobiera od użytkownika liczbę całkowitą a następnie n liczb całkowitych i zapisuje je do wektora.
//Następnie program powinien usunąć z wektora wszystkie duplikaty, zachowując jedynie unikalne elementy. Na końcu program powinien wyświetlić unikalne elementy w porządku ich wystąpienia.
#include <iostream>
#include <vector>
#include <ctime>
#include <set>
#include <time.h>
using namespace std;
int main(){
int a;
int n;
cout << "Podaj liczbe calkowita: ";
cin >> a;
vector<int> wektor = {a};
cout << "Ile jeszcze chcesz liczb? ";
cin >> n;
srand(static_cast<unsigned>(time(NULL)));
cout << "Wektor przed usunieciem duplikatow: " << endl;
for(int i = 0; i < n; i++){
wektor.push_back(rand() % 10);
}
for (int d : wektor)
{
cout << d << " ";
}
cout <<"." << endl;
set<int> uniqwe;
for(int c : wektor){
uniqwe.insert(c);
}
cout << "Wektor po sortowaniu oraz usunieciu duplikatow: " << endl;
for(int b : uniqwe){
cout << b << " ";
}
}