Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- #include <map>
- #include <deque>
- #include <thread>
- #include <algorithm>
- int main()
- {
- using namespace std;
- deque<int> ids = {4, 7, 0, 7, 1, 0, 1, 2, 1, 2, 6};
- enum { frame_size = 5 };
- typedef map<int, chrono::system_clock::time_point> MAP;
- MAP frame;
- while (!ids.empty())
- {
- int id = ids.front();
- ids.pop_front();
- if (frame.find(id) == frame.end())
- {
- if (frame.size() == frame_size)
- {
- auto it = min_element(frame.begin(), frame.end(),
- [] (MAP::const_reference left, MAP::const_reference right)
- {
- return left.second < right.second;
- });
- cout << it->first << " was erased\n";
- frame.erase(it);
- }
- frame[id] = chrono::system_clock::now();
- }
- this_thread::sleep_for(chrono::milliseconds(500));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement