You are viewing a single comment's thread. Return to all comments →
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; }
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 →
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; }