/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include <vector> #include <set> using namespace std; vector<int> v; set<int> s; void Add(){ int num = v.size(); int index = num - 1; s.insert(vindex); —index; while(True){ s.insert(vindex); while(True){ ++vindex; if(vindex > num){ —index; break; } auto it = s.find(vindex); if(it != s.end()){ s.erase(it); int i = 1; for(auto el : s){ vindex + i = el; ++i; } s.clear(); return; } } } } template <typename T> void print(const T& param){ for(auto p : param){ cout « p « " "; } cout « endl; } int main() { // v = {1, 4, 3, 2, 5}; // print(v); // Add(); // print(v); v = {1, 2, 3, 4, 5}; for(int i = 0; i < 119; ++i){ Add(); print(v); } return 0; }

Теги: C++ online compiler

Теги других блогов: C++ online compiler