Advertisement
Guest User

1

a guest
Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <string>
  5. int main() {
  6.     int amount, page;
  7.     std::string name;
  8.     std::cin >> amount;
  9.     std::map <std::string, std::set<int> > words_pages;
  10.     for (int i = 0; i != amount; i++) {
  11.         std::cin >> page >> name;
  12.         auto it = words_pages.find(name);
  13.         if (it != words_pages.end()) {
  14.             words_pages[name].insert(page);
  15.         } else {
  16.             std::pair<std::string, std::set<int> > aux;
  17.             aux.first = name;
  18.             aux.second.insert(page);
  19.             words_pages.insert(aux);
  20.         }
  21.     }
  22.     for (std::pair<std::string, std::set<int> > x : words_pages) {
  23.         std::cout << x.first << ' ';
  24.         for (auto it = x.second.begin(); it != x.second.end(); ++it) {
  25.             std::cout << *it;
  26.             if (it != --x.second.end()) {
  27.                 std::cout << ' ';
  28.             }
  29.         }
  30.         std::cout << std::endl;
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement