Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. //#include <fstream>
  4. #include <algorithm>
  5. #include <functional>
  6.  
  7. using namespace std;
  8.  
  9. typedef map<int, int>::iterator map_iter;
  10.  
  11. int k = 0;
  12. map<int, int> container;
  13.  
  14. int main() {
  15.     int elem;
  16.     int k_counter=0;
  17.     cin >> k;
  18.     while (true) {
  19.         cin >> elem;
  20.         if (elem == -1) {
  21.             break;
  22.         }
  23.         if (elem == 0) {
  24.             for (map_iter it = container.begin(); it != container.end(); ++it) {
  25.                 cout << it->first << " ";
  26.             }
  27.             if (container.size() < k - 1) {
  28.                 for (int i = 0; i < k - 1 - container.size(); ++i) {
  29.                     cout << 1 << " ";
  30.                 }
  31.             }
  32.             cout << endl;
  33.             continue;
  34.         }
  35.         ++container[elem];
  36.         if (container[elem] == 1) {
  37.             ++k_counter;
  38.         }
  39.         if (k_counter == k) {
  40.             for (map_iter it = container.begin(); it != container.end();) {
  41.                 it->second -= 1;
  42.                 if (it->second == 0) {
  43.                     --k_counter;
  44.                     map_iter temp = it;
  45.                     ++it;
  46.                     container.erase(temp);
  47.                     continue;
  48.                 }
  49.                 ++it;
  50.             }
  51.         }
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement