Created
May 7, 2019 14:39
-
-
Save lazycipher/6f6fd5be9c197e8190dcf53f74dab8d1 to your computer and use it in GitHub Desktop.
HackerRank Vector Erase Problem in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
vector<int> ins; | |
int n, erSingle, erRangeS, erRangeE; | |
cin>>n; | |
while(n){ | |
int val; | |
cin>>val; | |
ins.push_back(val); | |
n--; | |
} | |
cin>>erSingle; | |
ins.erase(ins.begin()+(erSingle-1)); | |
cin >> erRangeS >> erRangeE; | |
ins.erase(ins.begin()+erRangeS-1, ins.begin()+erRangeE-1); | |
cout<<ins.size()<<endl; | |
for(int i = 0; i<ins.size(); i++){ | |
cout<<ins[i]<<" "; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment