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.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>intmain(){intn{};std::cin>>n;// # of integersstd::vector<int>numbers{};numbers.resize(n);for(inti=0;i<n;i++){std::cin>>numbers[i];}intdelElement{};// position of element that should be removedstd::cin>>delElement;numbers.erase(numbers.begin()+(delElement-1));intdelFrom{};intdelTo{};std::cin>>delFrom;// deletion positionstd::cin>>delTo;intcounter{};// every step causes to move vector numbers leftfor(inti=delFrom;i<delTo;i++){numbers.erase(numbers.begin()+(i-1-counter));counter++;}std::cout<<numbers.size()<<'\n';for(inti:numbers){std::cout<<i<<' ';}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Vector-Erase
You are viewing a single comment's thread. Return to all comments →