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<stdio.h>
#include<string.h>
using namespace std;

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

int main(){
	
	int i,page;
	char inputStr[32];
	bool flag;
	struct book_info index[101]={'\0',0};
	
	memset(inputStr,'\0',sizeof(inputStr));
	
	
	//入力
	for(i=0;i<100;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<101;j++){
			for(int k=i-1;k>j;k--){
				if((index[g].pageNum[k-1]>index[g].pageNum[k]) && 
				    index[g].pageNum[k-1]!=0 &&
				    index[g].pageNum[k]!=0){		
						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<101 && index[j].pageNum[k]!=0;k++){
			if(index[j].pageNum[k+1]!=0){
				cout<<index[j].pageNum[k]<<" ";
			}else{
				cout<<index[j].pageNum[k]<<endl;
			}
		}
	}
}

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

typedef map<string,vector<int> > P;

int main()
{
    P p;
    string str;
    int t = 0;
    while (cin >> str >> t)
        p[str].push_back(t);
    P::iterator it;
    for (it = p.begin(); it != p.end(); it++) {
        sort(it->second.begin(), it->second.end());
        cout << it->first  << endl << it->second[0];
        for (int j = 1; j < it->second.size(); j++)
            cout << " " << it->second[j];
        cout << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
class data{
public:
  string words;  
  int page;
  bool operator < (const data& s)const{
    if(words < s.words) return true;
    else if(words > s.words) return false;
    else{
      if(page < s.page) return true;
      else return false;
    }
  }
};
int main(){
  int i=0;
  data in[1000];
  while(1){
    in[i].words="";
    char c;
    if(scanf("%c", &c)==EOF) break;
    in[i].words+=c;
    for(int j=1;;j++){
      scanf("%c", &c);
      if(c==' ') break;
      in[i].words+=c;
    }
    cin >> in[i].page;
    getchar();
    i++;
  }
  
  sort(in,in+i);

  cout << in[0].words << endl << in[0].page;
  for(int j=1;j<i;j++){
    if(in[j-1].words != in[j].words){
      cout << endl;
      cout << in[j].words << endl << in[j].page;
    }
    else{
      cout << ' ' << in[j].page;
    }
  }
  cout << endl;
  return 0;
}

C++: #include <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	map<string, vector<int> > index;
	pair<string, vector<int> > word_page;
	string word;
	int page;
	while( cin >> word >> page )
	{
		index[word].push_back(page);
	}

	for(map<string, vector<int> >::iterator it = index.begin(); it != index.end(); it++)
	{
		vector<int> v = it->second;
		sort(v.begin(), v.end());

		cout << it->first << endl;
		for(vector<int>::iterator itv = v.begin(); itv != v.end(); itv++)
		{
			cout << *itv << " ";
		}
		cout << endl;
	}

	return (0);
}

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

int main(){
	string s;
	int p;
	map<string, vector<int> > index;
	while(cin >> s >> p){
		index[s].push_back(p);
	}
	for(auto a: index){
		cout << a.first << endl;
		sort(a.second.begin(), a.second.end());
		for(int i=0; i<(int)a.second.size()-1; i++){
			cout << a.second[i] << " ";
		}
		cout << a.second.back() << endl;
	}
	return 0;
}

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

map<string,vector<int> > p;

int main()
{
    string str;
    int t;
    while (cin >> str >> t) p[str].insert(t);
    for (auto it = p.begin(); it != p.end(); it++) {
	auto s = it->second.bigen();
        cout << it->first  << endl << *s;
        for (++s; s != it->second.end(); s++)
            cout << " " << *s;
        cout << endl;
    }

    return 0;
}

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

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;
		std::sort(i->second.begin(), i->second.end());
		for (std::vector<int>::iterator j = i->second.begin(); j != i->second.end(); j++) {
			std::cout << *j << " ";
		}
		std::cout << std::endl;
	}
	return 0;
}