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 <vector>
#include <algorithm>
using namespace std;
int main(){
	string s;
	int p;
	map<string,vector<int> > index;
	while(cin>>s>>p) index[s].push_back(p);
	for(map<string,vector<int> >::iterator it=index.begin();it!=index.end();++it){
		cout<<(*it).first<<"\n";
		sort((*it).second.begin(),(*it).second.end());
		for(int i=0;i<(*it).second.size();++i)cout<<(*it).second[i]<<((i!=(*it).second.size()-1)?" ":"\n");
	}
	return 0;
}

C++: // 2011/01/13 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct bindex{
	string wrd;
	int pag;
};

int main()
{
	struct bindex ind[100];
	int n=0;

	while(!cin.eof()){
		string str;
		getline(cin, str);

		if(!str.empty()){
			istringstream ist(str);
			ist >> ind[n].wrd >> ind[n].pag;
			n++;
		}
	}

	for(int i=0; i<n-1; i++)
		for(int j=i+1; j<n; j++)
			if((ind[i].wrd>ind[j].wrd)||(ind[i].wrd==ind[j].wrd&&ind[i].pag>ind[j].pag)){
				string wrd_tmp = ind[i].wrd;
				int pag_tmp = ind[i].pag;
				ind[i].wrd = ind[j].wrd;
				ind[i].pag = ind[j].pag;
				ind[j].wrd = wrd_tmp;
				ind[j].pag = pag_tmp;
			}

	cout << ind[0].wrd << endl;
	cout << ind[0].pag;
	for(int i=1; i<n; i++)
		if(ind[i-1].wrd==ind[i].wrd){
			cout << ' ' << ind[i].pag;
		}
		else{
			cout << endl;
			cout << ind[i].wrd << endl;
			cout << ind[i].pag;
		}
	cout << endl;

	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	map<string,vector<int> > m;
	string s;
	vector<string> v;
	char c[1000];
	int n;
	while(~scanf("%s%d",c,&n)){
		s=string(c);
		if(m[s].size()==0)v.push_back(s);
		m[s].push_back(n);
	}
	sort(v.begin(),v.end());
	rep(i,v.size()){
		cout << v[i] << endl;
		int l=m[v[i]].size();
		rep(j,l)
			printf("%d%c",m[v[i]][j],j==l-1?'\n':' ');
	}
	return 0;
}

C++: #include<iostream>
//#include<algorithm>
#include<string>
using namespace std;
int main(){
  string s[100000];
  string a;
  int d[100000];
  int b;
  int count = 0;
  while(cin>>a>>b){
    s[count] = a;
    d[count] = b;
    count++;
  }
  for(int i=0;i<count;i++){
    for(int j=count-2;j>=i;j--){
      if(s[j]>s[j+1]){
	string mem = s[j];
	s[j] = s[j+1];
	s[j+1] = mem;
	int me = d[j];
	d[j] = d[j+1];
	d[j+1] = me;
      }
      else if(s[j]==s[j+1]&&d[j]>d[j+1]){
	string me = s[j];
	s[j] = s[j+1];
	s[j+1] = me;
	int mem = d[j];
	d[j] = d[j+1];
	d[j+1] = mem;
      }
    }
  }
  cout << s[0] << endl << d[0];
  for(int i=1;i<count;i++){
    if(s[i]==s[i-1]) cout << ' ' << d[i];
    else{
      cout << endl;
      cout << s[i] << endl << d[i];
    }
  }
  cout << endl;
  return 0;
}

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=101-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<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<pair<string,int>> str;
    string S;
    while(cin >> S){
        int d;
        cin >> d;
        str.push_back(make_pair(S,d));
    }
    sort(str.begin(),str.end());
    int N = str.size();
    for(int i=0; i<N; i++){
        cout << str[i].first << enld;
        cout << str[i].second;
        while(i+1<N and str[i].first == str[i+1].first){
            i++;
            cout << " " << str[i].second;
        }
        cout << enld;
    }
    return 0;
}

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

int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,!std::cin.eof()){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::sort((*m_it).second.begin(),(*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while(v_it!=(*m_it).second.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==(*m_it).second.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}
/*
Sample Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output for the Sample Input
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
*/