-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.cpp
More file actions
52 lines (51 loc) · 964 Bytes
/
2.cpp
File metadata and controls
52 lines (51 loc) · 964 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
47
48
49
50
51
52
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
bool Prime(int n) {
if (n == 0) return true;
if (n == 1 || n == 2) return true;
else
{
for (int i = 2; i <= sqrt(n); i++)
{
if (n % i == 0) return false;
}
}
return true;
}
bool Find(vector <int> new_vec, int k)
{
int counter = 0;
for (int i = 0; i < new_vec.size(); i++)
{
if (new_vec[i] == k) ++counter;
}
if (counter >= 2) return true;
return false;
}
vector <int> delete_elements(vector <int> array) {
vector <int> array2 = array;
for (int i = 0; i < array.size(); i++)
{
if (Prime(array[i]) && Find(array2, array[i]))
{
array.erase(array.begin() + (i--));
}
}
return array;
}
int main() {
int n; cin >> n;
vector <int> arr(n);
for (int i = 0; i < arr.size(); i++)
{
cin >> arr[i];
}
arr = delete_elements(arr);
for (int& newarray : arr)
{
cout << newarray << " ";
}
return 0;
}