We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- STL
- Vector-Erase
- Discussions
Vector-Erase
Vector-Erase
Sort by
recency
|
417 Discussions
|
Please Login in order to post a comment
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n; cin >> n; // vecot declare... vector v (n); // element input.. for(int i = 0; i < v.size(); i++) { cin >> v[i]; } int pos; cin >> pos; // delete element 4 (index-2) v.erase(v.begin() + (pos - 1)); int a, b; cin >> a >> b; // range delete 2 to 4 v.erase(v.begin() + (a-1), v.begin() + (b-1)); cout << v.size() << endl; for(int p: v) { cout << p << " "; } cout << endl; return 0; }
include
include
include
include
include
using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin>>n;
vector v(n);
}
Here is Vector-Erase problem solution in C++ - https://programmingoneonone.com/hackerrank-vector-erase-solution-in-cpp.html
include
include
include
include
include
using namespace std;
int main() { int N; cin>>N;//taking the size of vector vectorv; int i; //giving elements to the vector for (i=0; i>e; v.push_back(e); } int x; cin>>x; //erasing the vector v.erase(v.begin()+(x-1)); int a,b; cin>>a; cin>>b; //position deleting v.erase(v.begin()+(a-1),v.begin()+(b-1)); vector::iterator it; int count=0; for (it=v.begin(); it