-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectorErase.cpp
48 lines (41 loc) · 989 Bytes
/
vectorErase.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cmath>
#include <cstdio>
#include <vector>
#include<string>
#include<sstream>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
string line,itr;
int n;
cin>>n;
getline(cin,line,'\n');
string interm;
vector<int> tokens(n);
int x;
int a,b;
//stringstream for tokenizing the input
std::stringstream checkl(line);
int t;
while(getline(checkl,interm,' '))
{
t=stoi(interm);
tokens.push_back(t);
}
cout<<endl;
cin>>x;
cout<<endl;
cin>>a>>b;
//erase the elements in vector
tokens.erase(tokens.begin()+x-1);
tokens.erase(tokens.begin()+a-1,tokens.begin()+b-1);
cout<<tokens.size();
//output the vector element after erasing specific range of location
for(int i=0;i<tokens.size();i++)
{
cout<<tokens[i]<<" ";
}
return 0;
}