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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 20000000
string word[100];
vector<int> p[100];
int n=0;
int search(string s)
{
        for(int i=0;i<n;i++)
        {
                if(word[i]==s)return i;
        }
        return -1;
}
int main()
{
        while(1)
        {
                string s;
                int page;
                cin >> s >> page;
                if(search(s)!=-1)
                {
                        p[search(s)].pb(page);
                }
                else
                {
                        word[n]=s;
                        p[n].pb(page);
                        n++;
                }

        }
        string str;
        while(cin >> str)
        {
                int num=search(str);
                sort(p[num].begin(),p[num].end());
                for(int i=0;i<p[num].size();i++)
                {
                        cout << p[num][i];
                        if(i==p[num].size()-1)
                        {
                                cout << endl;
                        }
                        else
                        {
                                cout << ' ';
                        }
                }
        }
        return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main(void)
{
	map<string, vector<int> > index;
	vector<string> name;
	string key;
	int page;
	while((cin>>key>>page))
	{
		int flg=0;
		for(int f1=0;f1<name.size();f1++)
		{
			if(name[f1]==key)flg=1;
		}
		if(!flg)name.push_back(key);
		index[key].push_back(page);
	}
	sort(name.begin(),name.end());
	for(int f1=0;f1<name.size();f1++)
	{
		sort(index[name[f1]].begin(),index[name[f1]].end());
		cout<<name[f1]<<endl;
		for(int f2=0;f2<index[name[f1]].size();f2++)
		{
			cout<<index[name[f1]][f2]<<" ";
		}
		cout<<endl;
	}
	/*
	fflush(stdin);
	getchar();
	*/
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	while (cin >> a) {
		string b,h="";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a. length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k;
		for (int i = 0; i != d[k].size(); i++) {
			cout << " " << d[k][i];
		}
		cout << endl;
	}
}

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

int main() {
	map<string, set<int> > id;
	string w; int p;
	while(cin >> w >> p) id[w].insert(p);
	for(map<string, set<int> >::iterator itw=id.begin(); itw!=id.end(); ++itw) {
		cout << (*itw).first << endl;
		for(set<int>::iterator itp=(*itw).second.begin();
				itp!=(*itw).second.end(); ++itp) {
			cout << (itp==(*itw).second.begin()?"":" ") << *itp;
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string tn[1000];
int tp[1000][1000],tt[1000];
int main(){
	string a;
	int b,top=0;
	while(cin>>a>>b){
		bool t=true;
		for(int i=0;i<top;i++){
			if(tn[i]==a){
				t=false;
				tp[i][tt[i]]=b;
				tt[i]++;
			}
		}
		if(t==true){
			tn[top]=a;
			tp[top][0]=b;
			tt[top]=1;
			top++;
		}
		for(int i=0;i<top-1;i++){
			for(int j=top-1;j>i;j--){
				bool w=true;
				int k=0;
				while(true){
					if(tn[j][k]>tn[j-1][k])
						break;
					if(tn[j][k]<tn[j-1][k]){
						w=false;
						break;
					}
					k++;
					if(k==tn[j-1].size())
						break;
					if(k==tn[j].size()){
						w=false;
						break;
					}
				}
				if(w==false){
					string tmps=tn[j];
					tn[j]=tn[j-1];
					tn[j-1]=tmps;
					int tmph[100];
					for(int k=0;k<tt[j];k++)
						tmph[k]=tp[j][k];
					for(int k=0;k<tt[j-1];k++)
						tp[j][k]=tp[j-1][k];
					for(int k=0;k<tt[j];k++)
						tp[j-1][k]=tmph[k];
					int tmp=tt[j];
					tt[j]=tt[j-1];
					tt[j-1]=tmp;
				}
			}
		}
	}
	for(int i=0;i<top-1;i++){
			for(int j=top-1;j>i;j--){
				bool w=true;
				int k=0;
				while(true){
					if(tn[j][k]>tn[j-1][k])
						break;
					if(tn[j][k]<tn[j-1][k]){
						w=false;
						break;
					}
					k++;
					if(k==tn[j].size())
						break;
					if(k==tn[j-1].size()){
						w=false;
						break;
					}
				}
				if(w==false){
					string tmps=tn[j];
					tn[j]=tn[j-1];
					tn[j-1]=tmps;
					int tmph[100];
					for(int k=0;k<tt[j];k++)
						tmph[k]=tp[j][k];
					for(int k=0;k<tt[j-1];k++)
						tp[j][k]=tp[j-1][k];
					for(int k=0;k<tt[j];k++)
						tp[j-1][k]=tmph[k];
					int tmp=tt[j];
					tt[j]=tt[j-1];
					tt[j-1]=tmp;
				}
			}
		}
		for(int i=0;i<top;i++)
			sort(tp[i],tp[i]+tt[i]);
		for(int i=0;i<top;i++){
			cout<<tn[i]<<endl;
			cout<<tp[i][0];
			for(int j=1;j<tt[i];j++)
				cout<<" "<<tp[i][j];
			cout<<endl;
		}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(void) {
    map<string, vector<int>> hm;
    
    string name; int page;
    while(cin >> name >> page) {
        hm[name].push_back(page);
        //cout << "hm[" << name << "] = " << hm[name] << endl;
    }
    for(auto ite = hm.begin(); ite != hm.end(); ite++) {
        cout << ite->first << endl;
        sort(ite->second.begin(), ite->second.end());
        for(int r = 0; r < ite->second.size(); r++) {
            cout << ite->second[r];
            if(r == ite->second.size()-1) putchar('\n');
            else putchar(' ');
        }
    }
    return(0);
}