#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <vector>
#include <time.h>
using namespace std;
#undef DEBUG
#ifdef DEBUG
#define DEBUG_MSG(str) do {std::cout << str;} while(false)
#else
#define DEBUG_MSG(str) do { } while( false )
#endif
int solve(int N, bool useEraseRemoveIdiom){
// cout<<__cplusplus<<endl;
vector<int> v;
for (int i = 0; i < N; i++) {
v.push_back(i);
}
DEBUG_MSG("지우기 전: " << endl);
DEBUG_MSG("v.size(): " << v.size() << endl);
for (int i = 0; i < v.size(); i++) {
DEBUG_MSG(v[i] << " ");
}
DEBUG_MSG(endl);
auto logical_end = remove_if(v.begin(), v.end(), [](int i) { return i % 2 == 0; });
if(useEraseRemoveIdiom){
v.erase(logical_end, v.end());
}else{
for(int i=N-1; i>=0; --i){
if(v[i] % 2 == 0){
v.erase(v.begin() + i);
}
}
}
DEBUG_MSG("5번 인덱스 지운 후: " << endl);
DEBUG_MSG("v.size(): " << v.size() << endl);
for (int i = 0; i < v.size(); i++) {
DEBUG_MSG(v[i] << " ");
}
DEBUG_MSG(endl);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
time_t start = clock();
// solve(10000, false);
solve(10000, true);
cout << "Elapsed time: " << clock() - start << "ms" << endl;
return 0;
}
사용컴파일러버전: g++20,