1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #pragma once
- #include <iostream>
- #include <map>
- #include <utility>
- template<typename T1, typename T2 >
- inline void Print(const std::map<T1,T2>& cont)
- {
- for (const auto& [f,s] : cont)
- {
- std::cout << f << ":" <<s<<" ";
- }
- std::cout << std::endl;
- }
- //Ðåàëèçîâàòü ôóíêöèþ, ïðîðåæèâàþùóþ èñõîäíóþ ïîñëåäîâàòåëüíîñòü ñëåäóþùèì îáðàçîì :
- // êàæäîé ïîäïîñëåäîâàòåëüíîñòè èäåíòè÷íûõ îòñ÷åòîâ îñòàâèòü
- // òîëüêî ïåðâûé è ïîñëåäíèé îòñ÷åòû, à òàê æå êàæäûé n - íûé îòñ÷åò(n > 2).
- //Âûâåñòè íà ýêðàí ïîñëåäîâàòåëüíîñòü äî è ïîñëå ïðèìåíåíèÿ ôóíêöèè ïðîðåæèâàíèÿ.
- bool thin_out(std::map<int, int>& cont, int n)
- {
- bool fl = false;
- std::pair<const int,int>* first = &(*cont.begin());
- auto last = first;
- auto pattern = (*std::begin(cont)).second;;
- int count = 0;
- for (auto& x : cont)
- {
- if (pattern == x.second)
- {
- count++;
- last = &x;
- }
- else if (count >2)
- {
- int key = (first->first);
- for (int i = 2; i < count; i++)
- {
- ++key;
-
- if(i == n) continue;
-
- cont.erase(key);
-
- }
- pattern = x.second;
- first = &x;
- count = 1;
- fl = true;
- }
- else
- {
- pattern = x.second;
- first = &x;
- count = 1;
- }
- }
- return fl;
- }
|