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<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

int main(){

  string s;
  int n;
  typedef vector < int > vec;
  map < string, vec > mp;
  vector < string > v;
  
  while(cin >> s >> n){
    mp[s].push_back(n);
    v.push_back(s);
  }

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  for(int i=0;i<v.size();i++){
    sort(mp[v[i]].begin(), mp[v[i]].end());
    cout << v[i] << endl;
    for(int j=0;j<mp[v[i]].size()-1;j++) cout << mp[v[i]][j] << " ";
    cout << mp[v[i]][mp[v[i]].size()-1] << endl;
  }

}

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

class tWord{
public:
	friend tWord;
	string word;
	vector<int> page;
	tWord( string w );
	friend bool operator <( const tWord& l, const tWord& r ){
		return (strcmp(l.word.c_str(), r.word.c_str())<0);
	}
};
tWord::tWord( string w ){
	word = w;
	page.clear();
}

int main(){
	vector<tWord> words;
	string line;
	int n;
	char w[31];

	// input
	while(1){
		getline( cin, line );
		if( line.size()==0 ) break;
		sscanf(line.c_str(), "%s %d", w, &n);
		int i;
		for( i=0; i<words.size(); i++ ){
			if( words[i].word == w ){
				break;
			}
		}
		if( i == words.size() ){
			string ww = w;
			words.push_back(ww);
		}
		words[i].page.push_back(n);
	}

	// output
	sort( words.begin(), words.end() );
	for( int i=0; i<words.size(); i++ ){
		if( words[i].word != "" ){
			cout << words[i].word << endl;
			sort( words[i].page.begin(), words[i].page.end() );
			cout << words[i].page[0];
			for( int j=1; j<words[i].page.size(); j++ ){
				cout << " " << words[i].page[j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

struct BK{string st;int p;};
int main(){
string str;
int N,iii=0;
BK B[101],T;
while(cin>>str>>N){
B[iii].st=str;B[iii].p=N;
iii++;
}
for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st<B[j-1].st){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st==B[j-1].st&&B[j].p<B[j-1].p){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
{if(i==0)cout<<B[0].st<<" "<<B[0].p;
else if(i>0&&B[i].st==B[i-1].st){cout<<" "<<B[i].p;}
else cout<<endl<<B[i].st<<" "<<B[i].p;
}
return 0;
}

C++: #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<<"\b";
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)


int main(){
	vector<string> s;
	map<string,vector<int> > ma;
	string tmp;
	while(cin>>tmp){
		int t;
		cin>>t;
		ma[tmp].push_back(t);
		s.push_back(tmp);
	}
	sort(s.begin(),s.end());
	s.erase(unique(s.begin(),s.end()),s.end());
	rep(i,s.size()){
		cout<<s[i]<<endl;
		sort(ma[s[i]].begin(),ma[s[i]].end());
		rep(j,ma[s[i]].size()){
			if(j) cout<<" ";
			cout<<ma[s[i]][j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>

char voc[105][50], str[50], page[105][105];
char avoc[105][50], apage[105][105];

using namespace std;

int main(void)
{
	int n, i, j, k, c;
	
	i = 0;
	while (scanf("%s %d", str, &n) != EOF){
		
		c = 0;
		
		for (j = 0; j < i; j++){
			if (strcmp(str, voc[j]) == 0){
				
				k = 0;
				while (page[j][k] != 0){
					k++;
				}
				page[j][k] = n;
				c = 1;
			}
		}
		
		if (c == 0){
			strcpy(voc[i], str);
			page[i][0] = n;
			i++;
		}
	}
	
	for (j = 0; j < i; j++){
		for (k = 0; k < i - j - 1; k++){
			
			if (strcmp(voc[k], voc[k + 1]) > 0){
				strcpy(str, voc[k]);
				strcpy(voc[k], voc[k + 1]);
				strcpy(voc[k + 1], str);
				
				strcpy(str, page[k]);
				strcpy(page[k], page[k + 1]);
				strcpy(page[k + 1], str);
			}
		}
	}
	
	for (j = 0;j < i; j++){
		k = 0;
		while (page[j][k] != 0){
			k++;
		}
		sort(&page[j][0], &page[j][0] + k);
	}
	
	for (j = 0; j < i; j++){
		printf("%s\n", voc[j]);
		k = 0;
		
		while (1){
			printf("%d", page[j][k]);
			k++;
			
			if (page[j][k] == 0){
				break;
			}
			else{
				printf(" ");
			}
		}
		printf("\n");
	}
	
	return (0);
}

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

int main() {
	map<string, vector<int> > book;
	string title;
	int page;
	while(cin >> title >> page) {
		book[title].push_back(page);
	}
	for(map<string, vector<int> >::iterator itr = book.begin(); itr != book.end(); itr++) {
		printf("%s\n", (*itr).first.c_str());
		sort((*itr).second.begin(), (*itr).second.end());
		for(vector<int>::iterator sc = (*itr).second.begin(); sc != (*itr).second.end(); sc++) {
			printf("%d ", *sc);
		}
		printf("\n");
	}
	return 0;
}

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

int main() {

  map<string, vector<int> > m;
  string s;
  string data_s[101];
  int page;
  while( cin >> s >> page ) {
    m[s].push_back(page);
  }

  for( map<string, vector<int> >::iterator it = m.begin(); it != m.end(); it++) {
    cout << (*it).first << endl;
    sort((*it).second.begin(), (*it).second.end());
    for(int i=0; i<(*it).second.size()-1; i++) {
      cout << (*it).second[i] << " ";
    }
    cout << (*it).second[(*it).second.size()-1] << endl;
  }

}

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

struct W{
    string word;
    priority_queue<int> pq;
    bool operator < (const W& o) const {
        return word < o.word;
    }
};

W genW(string w, int p){
    W new_word;
    new_word.word = w;
    new_word.pq.push( -p );
    return new_word;
}

int main(){
    string w; int p;
    vector< W > ls;
    vector< W >::iterator it;
    while( cin >> w >> p ){
        it = ls.begin();
        for(; it != ls.end(); it++){
            if( it->word == w ){
                it->pq.push( -p );
                break;
            }
        }
        if( it == ls.end() ){
            ls.push_back( genW(w, p) );
        }
    }
    sort(ls.begin(), ls.end());
    for(it = ls.begin(); it!=ls.end(); it++){
        cout << it->word << endl;
        cout << -( it->pq.top() );
        it->pq.pop();
        while( !it->pq.empty() ){
            cout << ' ' << -( it->pq.top() );
            it->pq.pop();
        }
        cout << endl;
    }
    return 0;
}