forked from Lucifer6102/Hacktoberfest2k21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector_Erase.cpp
34 lines (29 loc) · 935 Bytes
/
Vector_Erase.cpp
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
/*
Contributor:Ankit Bhujeja
Problem statement: https://www.hackerrank.com/challenges/vector-erase/problem?isFullScreen=true
*/
int main() {
int n,element;
vector<int> vec;
cin>>n; //taking length of a vector
for(int i=0;i<n;i++){
cin>>element; //Taking elements of vector
vec.push_back(element);
}
int a,b,c;
cin>>a;
vec.erase(vec.begin()+a-1); //Remove the (a-1)th index element or ath element from vector
cin>>b>>c;
vec.erase(vec.begin()+b-1,vec.begin()+c-1); // Removing all elements falling in range of b and c
cout<<vec.size()<<endl;
for(int i=0;i<vec.size();i++){
cout<<vec[i]<<" "; //printing the vector
}
return 0;
}