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<stdio.h>
#include<string.h>
 
int main(void)
{
    int num[101], tempn, index[101][31], i, j, k, l, m, alc, count;
    char word[101][31],tempw[31],dict[101][31];
 
    i = 0;
    while (~scanf("%s %d", word[i], &num[i]))
        i++;
    i = i - 1;
    j = 0;  
    while (j < i)    
    {      
        if (strcmp(word[j], word[j+1]) > 0)
        {
            strcpy(tempw, word[j]);
            strcpy(word[j], word[j+1]);
            strcpy(word[j+1], tempw);
            tempn = num[j];
            num[j] = num[j+1];
            num[j+1] = tempn;      
            j=0;
        }    
        else
            j++;
    }
 
    l = 0;
    alc = 0;
    count = 0;
    for (k = 0; k <= i; k++)    
    {      
        if (k == 0)
        {      
            strcpy(dict[0], word[0]);
            index[0][0] = num[0];
            l++;
        }      
        else   
        {      
            if (strcmp(dict[l-alc-1], word[k]) != 0)
            {          
                count = 0;
                strcpy(dict[l-alc], word[k]);
                index[l-alc][0] = num[k];
                l++;
            }      
            else
            {
                count++;
                alc++;
                index[l-alc][count] = num[k];
                l++;
            }
        }
    }
    for (k=0;k<i;k++)
    {
        m = 0;
        while (index[k][m+1] != 0)
        {
            if (index[k][m] > index[k][m+1])
            {
                tempn = index[k][m];
                index[k][m] = index[k][m+1];
                index[k][m+1] = tempn;
                m = 0;
            }
            else
                m++;
        }
    }
    for (k = 0; k < l-alc; k++)
    {
        m = 0;
        printf("%s\n", dict[k]);
        while (index[k][m+1] != 0)
        {
            printf("%d ", index[k][m]);
            m++;
        }
        printf("%d\n", index[k][m]);
    }
 
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	string S;
	int N;
	multimap<int, string> mp;
	while( cin >> S >> N )
	{
		mp.emplace( make_pair( N, S ) );
	}
	multimap<string, int> mp2;
	for( auto &x: mp ){
		mp2.emplace( make_pair( x.second, x.first ) );
	}
	string tmp;
	bool flag = true;
	for( auto x : mp2 )
	{
		if( x.first == tmp )cout << " ";
		if( x.first != tmp )
		{
			if( !tmp.empty() )
			{
				cout << endl;
			}
			tmp = x.first;
			cout << x.first << endl;
		}
		cout << x.second;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <set>

using namespace std;

int main(void){
  map<string, set<int> > Index;
  int page;
  string name;
  
  while(cin >> name >> page){
    Index[name].insert(page);
  }
  
  for(map<string, set<int> >::iterator it = Index.begin() ; it != Index.end() ; it++){
    cout << (*it).first << endl;
    
    int i = 0;
    
    for(set<int>::iterator it2 = it->second.begin() ; it2 != it->second.end() ;
	it2++){
      if(it->second.size()-1 != i) cout << *it2 << " ";
      else cout << *it2 << endl;
      i++;
    }
  }
  return 0;
}

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

void Swap(int& x,int& y);
void SWAP(char *x,char *y);



class Book{
	int count;
	char name[1000][30];
	int page[100][100] = {{0}};
	int stock[100] = { 0 };
public:
	void Set(int x);
	void IN(char *str,int pa);
	void OUT();
	void SORT();
};

void Book::Set(int x){
	int i,j,k,tmp;
	if(x == 0)
		count = 0;
	else{
		for(i = 0; i < count; i++){
			for(j = 0; j < stock[i]; j++){
				for( k = stock[i] - 1; j < k ; k--){
					if(page[i][j] > page[i][k]){
						tmp = page[i][j];
						page[i][j] = page[i][k];
						page[i][k] = tmp;
					}
				}
			}
		}
	}
}

void Book::OUT(){
	int i,j;

	for(i = 0; i < count; i++){
		cout << name [i] << endl;
		for(j = 0; j < stock[i]; j++){
			if(j > 0)
				cout << ' ';
			cout << page[i][j];
		}
		cout << endl;
	}
}

void Book::IN(char *str,int pa){
	int i,j,k,f=0,tmp;

	for(i = 0; i < count; i++){
		if((strcmp(name[i],str)) == 0){
			f++;
			page[i][stock[i]] = pa;
			stock[i]++;
			break;
		}
	}
	if(f == 0){
		count++;
		strcpy(name[count-1],str);
		page[count-1][ 0 ] = pa; 
		stock[i]++;
	}
}

void Book::SORT(){
	int i,j,k,tmp2,max;
	char tmp1[100];

	i = 0;
	j = count;

	for(i = 0; i < j ; i++){
		for(j = count - 1; j > i ; j--){
			if((strcmp(name[i],name[j]))){
				strcpy(tmp1,name[i]);
				strcpy(name[i],name[j]);
				strcpy(name[j],tmp1);

				if(stock[i] < stock[j]){
					for(k = stock[i]; k < stock[j]; k++)
						page[i][k] = page[j][k];
					max = stock[i];
				}
				else{
					for(k = stock[j]; k < stock[i]; k++)
						page[j][k] = page[i][k];
					max = stock[j];
				}

				for(k = 0; k < max ; k++){
					tmp2 = page[j][k];
					page[j][k] = page[i][k];
					page[i][k] = tmp2;
				}

				tmp2 = stock[i];
				stock[i] = stock[j];
				stock[j] = tmp2;
			}
		}
	}
}
 

int main(){
	int i,j,num;
	char str[30];
	Book index;


	index.Set(0);
	while(1){
		cin >> str;
		if( cin.eof() )break;
		cin >> num;

		index.IN(str,num);
	}
	index.Set(1);
	index.SORT();
	
	index.OUT();

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	string word;
	int page;
	map<string, vector<int> > index;

	while ( cin >> word >> page )
	{
		index[ word ].PB( page );
	}
	
	IREP( index, it )
	{
		cout << (*it).fst << endl;

		sort( ALL( (*it).snd ) );

		REP( i, 0, (*it).snd.size() )
		{
			cout << (*it).snd[i] << ( i + 1 == (*it).snd.size() ? '\n' : ' ' );
		}
	}

	return 0;
}