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;
int main (int argc, char *argv[]) {
	map<string,vector<int> > dict;
	string word;
	int page_num;
	while (cin >> word >> page_num) {
		// New
		if (dict.count(word) == 0) {
			dict.insert(make_pair(word,vector<int>(1,page_num)));
		}
		// Add
		else {
			dict[word].push_back(page_num);
		}
	}
	map<string,vector<int> >::iterator it = dict.begin();
	while (it != dict.end()) {
		cout << it->first << endl;
		vector<int> sorted = it->second;
		sort(sorted.begin(), sorted.end());
		for(int i = 0; i < sorted.size(); ++i) {
			cout << sorted[i];
			if (i != sorted.size()-1) cout << " ";
		}
		cout << endl;
		it++;
	}
	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<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

void sort(int x[102]){
    rep(i,102){
        rep(j,102){
            bool c = true;
            if(x[j] > x[j + 1]){
                int temp = x[j];
                x[j] = x[j + 1];
                x[j + 1] = temp;
                c = false;
            }
            if(c) break;
        }
    }
}

int main(){
    string word;
    int page, pageList[102][102], index = 1;
    rep(i,102) rep(j,102) pageList[i][j] = 5000;
    map<string,int> info;
    while(cin >> word >> page){
        if(info[word] > 0 && info[word] <= 102){
        }else{
            info[word] = index;
            index++;
        }
        int i = 0;
        while(true){
            if(pageList[ info[word] ][i] == 5000){
                pageList[info[word]][i] = page;
                break;
            }
            i++;
        }
    }
    rep(i,102){
        sort(pageList[i]);
    }
    map<string, int>::iterator it;
    for(it = info.begin(); it != info.end(); it++){
        cout << it->first << endl;
        rep(i,102){
            if(pageList[ it->second ][i] < 5000){
                if(i) cout << ' ';
                cout << pageList[ it->second ][i];
            }else break;
        }
        cout << endl;
    }
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

struct book_info{
	char phrase[32];
	int pageNum[101];
};

int main(){
	
	int i,page;
	char inputStr[32];
	bool flag;
	struct book_info index[101]={'\0',-1};
	
	memset(inputStr,'\0',sizeof(inputStr));
	
	
	//入力
	for(i=0;i<101;i++){
		
		if(scanf("%s %d",inputStr,&page)==EOF){
			break;
		}
		
		flag=true;
		
		//入力済みの単語かどうかを調べる
		int j;
		for(j=0;j<i;j++){
			//入力済みなら
			if(strcmp(index[j].phrase,inputStr)==0){
				//ページ番号の記憶
				for(int k=0;k<100;k++){
					if(index[j].pageNum[k]==0){
						index[j].pageNum[k]=page;
						break;
					}
				}
				
				flag=false;
				break;
			}
		}
		
		//入力されてないなら
		if(flag){
				strcpy(index[j+1].phrase,inputStr);
				index[j+1].pageNum[0]=page;
		}
		
		memset(inputStr,'\0',sizeof(inputStr));
	}
	
	
	//単語昇順バブルソート
	for(int j=0;j<i;j++){
		for(int k=i-1;k>j;k--){
			if(strcmp(index[k-1].phrase,index[k].phrase)>0){
				   struct book_info temp;
				   temp=index[k];
				   index[k]=index[k-1];
				   index[k-1]=temp;				
			}
		}
	}
	
	//単語昇順かつページ番号昇順バブルソート
	for(int g=0;g<i;g++){
		for(int j=0;j<100;j++){
			for(int k=100-1;k>j;k--){
				if((index[g].pageNum[k-1]>index[g].pageNum[k]) && 
				    index[g].pageNum[k-1]!=-1 &&
				    index[g].pageNum[k]!=-1){		
						int temp;
						temp=index[g].pageNum[k];
						index[g].pageNum[k]=index[g].pageNum[k-1];
						index[g].pageNum[k-1]=temp;				
				}
			}
		}
	}
	
	for(int j=0;j<i;j++){
		if(index[j].phrase[0]!='\0'){
			cout<<index[j].phrase<<endl;
		}
		for(int k=0;k<100 && index[j].pageNum[k]!=-1;k++){
			if(index[j].pageNum[k+1]!=-1){
				cout<<index[j].pageNum[k]<<" ";
			}else{
				cout<<index[j].pageNum[k]<<endl;
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define S first
#define I second

using namespace std; 

typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
 
int main(void){
    vector<psi> t;
    for(psi in; cin >> in.S >> in.I; t.pb(in));
   
    sort(ALL(t));

    string pre;
    each(t, it){
        if(it->S != pre) cout << (it != t.begin() ? "\n":"") << it->S << endl;
        cout << (pre == it->S ? " ":"") << it->I;
        pre = it->S;
    }
    cout << endl;
 
    return 0;
}

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

typedef struct{
	int jun;
	string tango;
	vector<int> page;
}sakuin;

int main(){
	vector<string> words;
	sakuin pages[100];
	string word;
	int num;
	int all;
	bool flag;

	cin >> word >> num;
	words.push_back(word);
	pages[0].jun = 0;
	pages[0].tango = word;
	pages[0].page.push_back(num);
	all = 1;

	while(cin >> word >> num){
		flag = true;
		for(int j=0;j<all;j++){
			if(pages[j].tango == word){
				pages[j].page.push_back(num);
				sort(pages[j].page.begin(),pages[j].page.end());
				flag = false;
				break;
			}
		}
		if(flag){
			words.push_back(word);
			sort(words.begin(),words.end());
			all++;
			for(int i=0;i<all;i++){
				if(words[i] == word){
					pages[all-1].jun = i;
					pages[all-1].tango = word;
					pages[all-1].page.push_back(num);

					for(int j=i+1;j<all;j++){
						for(int k=0;k<all;k++){
							if(words[j] == pages[k].tango)
								pages[k].jun += 1;
						}
					}
					break;
				}
			}
		}
	}

	for(int i=0;i<all;i++){
		for(int j=0;j<all;j++){
			if(pages[j].jun == i){
				cout << pages[j].tango << endl;
				for(unsigned int k=0;k<pages[j].page.size();k++){
					cout << pages[j].page[k];
					if(k+1<pages[j].page.size()) cout << ' ';
				}
				cout << endl;
				break;
			}
		}
	}
	return 0;
}