Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	index := make(map[string]string)
	keys := []string{}
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		if index[l[0]] == "" {
			keys = append(keys, l[0])
		}
		index[l[0]] += l[1] + " "
	}
	sort.Strings(keys)
	for _, k := range keys {
		fmt.Println(k)
		p := strings.Split(strings.TrimRight(index[k], " "), " ")
		pages := []int{}
		for _, v := range p {
			i, _ := strconv.Atoi(v)
			pages = append(pages, i)
		}
		sort.Ints(pages)
		for i, v := range pages {
			if i > 0 {
				fmt.Printf(" ")
			}
			fmt.Printf("%d", v)
		}
		fmt.Println()
	}
}

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

using namespace std;

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

    while(cin>>word>>page) {
        pages[word].push_back(page);
    }

    for(auto& e : pages) {
        sort(e.second.begin(), e.second.end());
    }

    for(auto& e :pages) {
        cout<<e.first<<endl;
        for(auto& v: e.second) {
            cout<<v<<" ";
        }
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;pair<string,int> a[100];int main(){int t=0,g,i;while(cin>>a[t].first>>a[t].second)t++;sort(a,a+t);string f,b=a[0].first;cout<<b<<endl<<a[0].second;for(i=1;i<t;i++){bool n=0;f=a[i].first,g=a[i].second;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<size-1i++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;
  }
}

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;
}