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<string>
#include<map>
#include<set>
using namespace std;main(int n,string s){map<string,set<int> >z;map<string,set<int> >::iterator q;set<int>::iterator x;while(cin>>s>>n)z[s].insert(n);for(q=z.begin();q!=z.end();cout<<endl){cout<<(s=q++->first)<<endl;for(x=z[s].begin(),n=0;x!=z[s].end();cout<<*x++)if(n++)cout<<" ";}return 0;}

C++: #include<stdio.h>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	map < string, vector<int> > index;

	char cbuf[31];
	int ibuf;

	while (scanf_s("%s %d", cbuf, 31, &ibuf) != EOF)
	{
		index[cbuf].push_back(ibuf);
	}

	for (auto &elem : index)
	{
		sort(elem.second.begin(), elem.second.end());
		printf_s("%s\n", elem.first.c_str());
		for (auto &vecElem : elem.second)
		{
			printf_s("%d ", vecElem);
		}
		printf_s("\n");
	}

	return 0;
}

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

typedef struct{
	std::string word;
	std::vector<int> page;
}Index;

bool operator<(const Index& x, const Index& y) { return x.word < y.word ;}


int main(void){
	int i, page;
	std::string word;

	std::vector<Index> Books;

	int NoW = 0;
	while(std::cin >> word >> page){
		for(i=0;i<NoW;i++){
			if(Books[i].word==word){
				Books[i].page.insert(Books[i].page.end(), page);
				break;
			}
		}
		if(i==NoW){
			Index temp;
			temp.word = word;
			temp.page.insert(temp.page.begin(), page);
			Books.insert(Books.end(), temp);
			NoW++;
		}
	}
	
	std::sort(Books.begin(), Books.end());

	for(unsigned int i=0;i<Books.size();i++){
		std::sort(Books[i].page.begin(), Books[i].page.end());
	}

	for(unsigned int i=0;i<Books.size();i++){
		std::cout << Books[i].word << std::endl;
		for(unsigned int j=0;j<Books[i].page.size();j++){
			std::cout << Books[i].page[j];
		}
		std::cout << std::endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>


using namespace std;

void Solution()
{
    map<string, set<int>> saveData;  //set の中には、各要素がソートされて格納されます。
    string str;
    int n;
    
    while (cin>>str>>n)
    {
        saveData[str].insert(n); // insert int type data to STL
    }
    
    for (map<string, set<int>>::iterator i = saveData.begin(); i != saveData.end(); i++)
    {
        cout<<(i -> first)<<endl;
        
        for (set<int>::iterator j = (i ->second).begin(); j != (i -> second).end(); j++)
        {
            if(j != (i -> second).begin()) // after output the first data, then can be divided by space keey.
            {
                cout<<" ";
            }
            
            cout<< *j;
        }
        
        cout<<endl;
    }
    
}

int main()
{
    Solution();
    return 0;
}

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

typedef std::pair<std::string,int> pa;
std::vector<pa>index;

int main(){
	std::string str;
	int page;
	while(std::cin>>str>>page){
		pa a;
		a.first=str,a.second=page;
		index.push_back(a);
	}
	std::sort(index.begin(),index.end());

	std::string d=index[0].first;
	std::cout<<d<<std::endl;
	std::cout<<index[0].second;

	for(int i=1;i<index.size();i++){
		if(index[i].first==d)std::cout<<" "<<index[i].second;
		else{
			std::cout<<std::endl;
			d=index[i].first;
			std::cout<<d<<std::endl;
			std::cout<<index[i].second;
		}
	}
	std::cout<<std::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 <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <bitset>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main(){
    vector<string> v;
    vector<vector<int>> count;
    string s;
    int n;
    for(int i=0;cin>>s>>n;i++){
        if(i==0){
            v.pb(s);
            count.pb(vector<int>(1,n));
        }else {
            bool f=true;
            rep(i,0,v.size()){
                if(v[i]==s){
                    count[i].pb(n);
                    f=false;
                }
            }
            if(f){
                v.pb(s);
                count.pb(vector<int>(1,n));
            }
        }
    }
    
    rep(i,0,count.size())Sort(count[i]);
    
    rep(i,0,v.size()-1){
        rep(j,i+1,v.size()){
            if(v[i]<v[j]){
                string temp=v[i];
                v[i]=v[j];
                v[j]=temp;
                
                count[i].swap(count[j]);
            }
        }
    }
    
    for(int i=v.size()-1;i>=0;i--){
        cout<<v[i]<<endl;
        rep(j,0,count[i].size()){
            if(j!=0)cout<<" ";
            cout<<count[i][j];
        }
        cout<<endl;
    }
    
    return 0;
}

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

using namespace std;

string char_to_str(char *c) {
	string ret = "";

	for (; *c; ++c)
		ret += *c;

	return ret;
}

int main() {
	map<string, vector<int> > m;
	vector<string> words;

	char word[50]; int page;
	while (scanf("%s%d\n", word, &page) != EOF) {
		string str = char_to_str(word);
		m[str].push_back(page);
		words.push_back(str);
	}

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

	for (int i = 0; i < words.size(); ++i) {
		vector<int> v = m[words[i]];
		sort( v.begin(), v.end() );

		cout << words[i] << endl;
		for (int j = 0; j < v.size(); ++j) {
			cout << v[j];
			if (j+1 < v.size()) cout << " ";
		}
		cout << endl;
	}
}