본문 바로가기
C++

[HackerRank]Vector-Erase-Easy

by 호아나트 2019. 10. 29.
반응형

https://www.hackerrank.com/challenges/vector-erase/problem

 

Vector-Erase | HackerRank

Erasing an element from a vector.

www.hackerrank.com

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n;
    vector<int> v;
    int res;
    int target1,target2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>res;
        v.push_back(res);

    }
    
    cin>>target1;
       v.erase(v.begin()+(target1-1));
    cin>>target1>>target2;

    v.erase(v.begin()+(target1-1),v.begin()+(target2-1));
    cout<<v.size()<<endl;
    for(vector<int>::iterator it =v.begin();it!=v.end();it++)
    {
        cout<<*it<<' ';
    }
    return 0;
   
}
반응형

'C++' 카테고리의 다른 글

[HackerRank]Vector-Sort - Easy  (0) 2019.10.29
[HackerRank] Virtual Functions -Medium  (0) 2019.10.28
[HackerRank] Exceptional Server - Easy  (0) 2019.10.25
[HackerRank] Inherited Code - Easy  (0) 2019.10.25
[HackerRank] Box it! - easy  (0) 2019.10.23

댓글