Header.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <iostream>
  3. #include <map>
  4. #include <utility>
  5. template<typename T1, typename T2 >
  6. inline void Print(const std::map<T1,T2>& cont)
  7. {
  8. for (const auto& [f,s] : cont)
  9. {
  10. std::cout << f << ":" <<s<<" ";
  11. }
  12. std::cout << std::endl;
  13. }
  14. //Ðåàëèçîâàòü ôóíêöèþ, ïðîðåæèâàþùóþ èñõîäíóþ ïîñëåäîâàòåëüíîñòü ñëåäóþùèì îáðàçîì :
  15. // êàæäîé ïîäïîñëåäîâàòåëüíîñòè èäåíòè÷íûõ îòñ÷åòîâ îñòàâèòü
  16. // òîëüêî ïåðâûé è ïîñëåäíèé îòñ÷åòû, à òàê æå êàæäûé n - íûé îòñ÷åò(n > 2).
  17. //Âûâåñòè íà ýêðàí ïîñëåäîâàòåëüíîñòü äî è ïîñëå ïðèìåíåíèÿ ôóíêöèè ïðîðåæèâàíèÿ.
  18. bool thin_out(std::map<int, int>& cont, int n)
  19. {
  20. bool fl = false;
  21. std::pair<const int,int>* first = &(*cont.begin());
  22. auto last = first;
  23. auto pattern = (*std::begin(cont)).second;;
  24. int count = 0;
  25. for (auto& x : cont)
  26. {
  27. if (pattern == x.second)
  28. {
  29. count++;
  30. last = &x;
  31. }
  32. else if (count >2)
  33. {
  34. int key = (first->first);
  35. for (int i = 2; i < count; i++)
  36. {
  37. ++key;
  38. if(i == n) continue;
  39. cont.erase(key);
  40. }
  41. pattern = x.second;
  42. first = &x;
  43. count = 1;
  44. fl = true;
  45. }
  46. else
  47. {
  48. pattern = x.second;
  49. first = &x;
  50. count = 1;
  51. }
  52. }
  53. return fl;
  54. }