Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- //#include <fstream>
- #include <algorithm>
- #include <functional>
- using namespace std;
- typedef map<int, int>::iterator map_iter;
- int k = 0;
- map<int, int> container;
- int main() {
- int elem;
- int k_counter=0;
- cin >> k;
- while (true) {
- cin >> elem;
- if (elem == -1) {
- break;
- }
- if (elem == 0) {
- for (map_iter it = container.begin(); it != container.end(); ++it) {
- cout << it->first << " ";
- }
- if (container.size() < k - 1) {
- for (int i = 0; i < k - 1 - container.size(); ++i) {
- cout << 1 << " ";
- }
- }
- cout << endl;
- continue;
- }
- ++container[elem];
- if (container[elem] == 1) {
- ++k_counter;
- }
- if (k_counter == k) {
- for (map_iter it = container.begin(); it != container.end();) {
- it->second -= 1;
- if (it->second == 0) {
- --k_counter;
- map_iter temp = it;
- ++it;
- container.erase(temp);
- continue;
- }
- ++it;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement