Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- #include <string>
- int main() {
- int amount, page;
- std::string name;
- std::cin >> amount;
- std::map <std::string, std::set<int> > words_pages;
- for (int i = 0; i != amount; i++) {
- std::cin >> page >> name;
- auto it = words_pages.find(name);
- if (it != words_pages.end()) {
- words_pages[name].insert(page);
- } else {
- std::pair<std::string, std::set<int> > aux;
- aux.first = name;
- aux.second.insert(page);
- words_pages.insert(aux);
- }
- }
- for (std::pair<std::string, std::set<int> > x : words_pages) {
- std::cout << x.first << ' ';
- for (auto it = x.second.begin(); it != x.second.end(); ++it) {
- std::cout << *it;
- if (it != --x.second.end()) {
- std::cout << ' ';
- }
- }
- std::cout << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement