Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dictionary := make(map[string][]int)

	for {
		var word string
		var page int
		fmt.Scanf("%s %d", &word, &page)

		if word == "" || page == 0 {
			break
		}

		pages := dictionary[word]
		pages = append(pages, page)
		dictionary[word] = pages
	}

	words := make([]string, 0)
	for i := range dictionary {
		words = append(words, i)
	}

	sort.Strings(words)

	for _, v := range words {
		sort.Ints(dictionary[v])
		fmt.Println(v)
		for i, page := range dictionary[v] {
			if i == len(dictionary[v])-1 {
				fmt.Printf("%d\n", page)
			} else {
				fmt.Printf("%d ", page)
			}
		}
	}
}

C++: #include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define MAX_N 101

string name[MAX_N];
int page[MAX_N];
map<string, int> m;
vector<int> vec;

int main(){
    int i = 0;
    while(cin >>name[i] >>page[i]){
        if(m.find(name[i]) == m.end()) m[name[i]] = 1;
        i++;
    }
    for(map<string, int>::iterator it = m.begin(); it != m.end(); it++){
        string searchName = (*it).first;
        cout <<searchName <<endl;
        for(int j = 0; j < i; j++){
            if(name[j] == searchName) vec.push_back(page[j]);
        }
        sort( vec.begin(), vec.end() );
        for(int i = 0; i < vec.size() - 1; i++){
            cout <<vec[i] <<" ";
        }
        cout <<vec[vec.size() - 1] <<endl;
        vec.clear();
    }
    return 0;
}

C++: #pragma warning(disable:4996)
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;

int main(){
	string word;
	int page;
	map<string, set<int>> indexs;
	while (cin >> word >> page){
		indexs[word].insert(page);
	}
	for (auto index : indexs){
		cout << index.first << endl;
		for (auto page_a : index.second){
			cout << page_a;
			if (*(index.second.rbegin()) != page_a)
				cout << " ";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main(){
    unordered_map<string, int> mp;
    vector<vector<int>> index(1,vector<int>());
    string str;
    vector<string> what;
    int page, pages = 1;
    while(cin >> str >> page){
        if(mp[str] == 0){
            mp[str] = pages;
            vector<int> newin(1, page);
            index.push_back(newin);
            what.push_back(str);
            pages++;
        }
        else{
            index[mp[str]].push_back(page);
        }
    }
    sort(what.begin(), what.end());
    for(int i = 0;i<what.size();i++){
        str = what[i];
        sort(index[mp[str]].begin(), index[mp[str]].end());
        cout << str << endl;
        for (int i = 0; i < index[mp[str]].size();i++){
            if(i == index[mp[str]].size()-1){
                cout << index[mp[str]][i] << endl;
            }
            else{
                cout << index[mp[str]][i] << " ";
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>

using namespace std;

char returnc(char c){
  if('a'<=c && c<='z'){
    if(c=='z')return 'a';
    return ++c;
  }
  return c;
}
int main(void){
  string s;
  int n;
  vector<string> ss;
  vector<vector<int> > nn;
  while(cin>>s>>n){
    if(ss.empty()){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
    }
    bool ok = true;
    for(int i = 0 ; i < ss.size() ; i ++){
      if(ss[i] == s){
	nn[i].push_back(n);
	ok = false;
      }
    }
    if(ok){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      
    }
  }
  for(int i = ss.size() - 1 ; i >= 0 ; i --){
    for(int j = 0 ; j < i ; j ++){
      if(ss[i] < ss[j]){
	string w = ss[i];
	ss[i] = ss[j];
	ss[j] = w;
	vector<int> ws = nn[i];
	nn[i] = nn[j];
	nn[j] = ws;
      }
    }
  }
  
  for(int i = 0 ; i < ss.size() ; i ++){
    cout<<ss[i]<<endl;
    for(int j = 0 ; j < nn[i].size()-1 ; j ++){
      cout<<nn[i][j]<<" ";
    }
    cout<<nn[i][nn[i].size() - 1 ]<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int n;
    std::deque<string> words;
    std::multimap<string, int> map;
    std::map<string, int> seen;
    while (cin>>s) {
        if (cin.fail()) {
            break;
        } else {
            cin>>n;
        }
        if (seen[s]==0) {
            words.emplace_back(s);
            seen[s]++;
        }
        map.insert(make_pair(s,n));
    }
    sort(words.begin(),words.end());
    for (int i=0;i<words.size();i++) {
        cout<<words[i]<<endl;
        std::deque<int> tmp;
        auto p=map.equal_range(words[i]);
        for (auto itr=p.first;itr!=p.second;itr++) {
            tmp.emplace_back(itr->second);
        }
        sort(tmp.begin(),tmp.end());
        for (int i=0;i<tmp.size();i++) {
            cout<<tmp[i];
            if (i!=tmp.size()-1) {
                cout<<" ";
            } else {
                cout<<endl;
            }
        }
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>

typedef std::map<std::string, std::vector<int> > index_t;
typedef std::pair<std::string, std::vector<int> > info_t;

index_t index;

std::string word;
int page_num;
bool get_input()
{
	return (std::cin >> word >> page_num);
}

int main()
{
	index_t::iterator word_itr;
	while (get_input()) {
		word_itr = index.find(word);
		if (word_itr == index.end()) {
			std::vector<int> page_nums;
			page_nums.push_back(page_num);
			info_t info(word, page_nums);
			index.insert(info);
		} else {
			word_itr->second.push_back(page_num);
		}
	}
	for (index_t::iterator i = index.begin(); i != index.end(); i++) {
		std::cout << i->first << std::endl;
		for (std::vector<int>::iterator j = i->second.begin(); j != i->second.end(); j++) {
			std::cout << *j << " ";
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main(){
	string s;
	int n;
	map<string, vector<int> > m;
	while (1){
		if (cin.eof()) break;
		cin >> s >> n;
		m[s].push_back(n);
	}
	map<string, vector<int> >::iterator it = m.begin();
	while (it != m.end()){
		int flag = 0;
		cout << (*it).first << endl;
		sort((*it).second.begin(), (*it).second.end());
		for (int i = 0; i < (*it).second.size(); i++){
			if (!flag){
				cout << (*it).second[i];
				flag = 1;
			}
			else cout << " " << (*it).second[i];
		}
		cout << endl;
		++it;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

map<string, vector<int> > list;
vector<string> names;
map<string, bool> check;

int main(void){
	string S;
	int n;
	while(cin >> S >> n){
		list[S].push_back(n);
		names.pb(S);
	}
	sort(names.begin(), names.end());
	rep(i, names.size()){
		S = names[i];
		if(check[S])continue;
		sort(list[S].begin(), list[S].end());
		cout << S << endl;
		rep(i, list[S].size()){
			if(i != 0)cout << " ";
			cout << list[S][i];
		}
		check[S] = true;
		cout << endl;
	}
	

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}