-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayTaskVector.cpp
More file actions
65 lines (59 loc) · 1.74 KB
/
Copy patharrayTaskVector.cpp
File metadata and controls
65 lines (59 loc) · 1.74 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
64
65
#include <iostream>
#include <vector>
using namespace std;
bool fiveInInt(int c){ //checking whether the number contains 5
while(c > 0){
int t = c % 10;
if(t == 5) return true;
c /= 10;
}
return false;
}
int main(){
int n;
cin >> n;
vector<int> a (n);
for(int i = 0; i < n; i++){ // array input
cin >> a[i];
}
bool descending = true; //checking whether the array is descending (wow tabnine really knows what I want)
for(int i = 1; i < n && descending; i++){
if(a[i] >= a[i-1]) descending = false;
}
vector<int> deletedA(n);
if(!descending){ //deleting five containing integers by copying needed elements into the new one
int ind = 0;
for(int i = 0; i < n; i++){
if(!fiveInInt(a[i])){
deletedA[ind] = a[i];
ind++;
}
}
deletedA.resize(ind);
deletedA.shrink_to_fit();
a.clear(); //in this case it's actually useless, but now you know that I can clear memory :)
a.shrink_to_fit();
for(int i = 0; i < deletedA.size(); i++){
cout << deletedA[i] << " ";
}
}
else{
cout << "array is descending insert new element" << endl;
int t;
cin >> t;
bool notInserted = true;
for(int i = 0; i < n && notInserted; i++){ //inserting new element in front of the first that is lower than the new element
if(a[i] < t){
a.insert(a.begin() + i, t);
notInserted = false;
}
}
if(notInserted){
a.insert(a.end(), t);
}
for(int i = 0; i < a.size(); i++){
cout << a[i] << " ";
}
}
return 0;
}