Vector erase question - click here
Solution :
Go to the description to see the answer as in the question, the things aren't proper and output isn't clear.
The question is 1-indexed.
Code :
#include<iostream>
#include<vector>
using namespace std;
int main(){
vector<int> v;
int size;
int n;
cin>>size;
for(int i=0;i<size;i++){
cin>>n;
v.push_back(n);
}
int pos;
cin>>pos;
int a, b;
cin>>a>>b;
v.erase(v.begin()+pos-1);
v.erase(v.begin()+a-1, v.begin()+b-1);
cout<<v.size()<<endl;
int x = v.size();
for(int i=0;i<x;i++)
cout<<v[i]<<" ";
return 0;
}
No comments:
Post a Comment