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++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1001
#define _MAX 100
#define HO 6
int main(void)
{
	char str[MAX];
	string word[_MAX];
	int pa[_MAX], rank[_MAX], cou, a;
	for (cou = 0; scanf_s("%s %d", str, MAX, &pa[cou]) != EOF;++cou) {
		string wo(str);
		word[cou] = wo;
		rank[cou] = cou;
	}
	for (int i = 0; i < cou; ++i) {
		for (int j = cou - 1; j > i; --j) {
			if (word[rank[j]] >= word[rank[j - 1]]) {
				if (word[rank[j]] == word[rank[j - 1]]) {
					if (pa[rank[j]] > pa[rank[j - 1]]) {
						a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
					}
				}
				else {
					a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
				}
			}
		}
	}
	for (int i = 0; i < cou; ++i) {
		if(i == 0 || word[rank[i - 1]] != word[rank[i]]) 
		cout << word[rank[i]] << "\n";
		if (i != 0 && word[rank[i - 1]] != word[rank[i]])
			printf(" ");
		printf("%d", pa[rank[i]]);
		if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]])
			printf("\n");
	}
	printf("\n");

}

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

int main(){
  string s;
  int page;
  map<string , vector<int> > dict;
  while ( cin >> s >> page )
    {
    dict[ s ].push_back( page );
  }
  for ( map<string, vector<int> >::iterator it = dict.begin(); it != dict.end(); it++ )
    {
      cout << it->first << endl;
      sort( it->second.begin(), it->second.end() );
      int i = 0;
      for ( vector<int>::iterator itv = it->second.begin() ; itv != it->second.end(); itv++, i++ )
	{
	  if(i)cout << " ";
	  cout << *itv;
	}
      cout << endl;
    }
  return 0;
}

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

int main()
{
    std::map<std::string, std::vector<int> > BookIndex;
    std::string word;
    int page;

    while (std::cin >> word >> page) {
        if (BookIndex.count(word)) {
            BookIndex[word].push_back(page);
        } else {
            BookIndex[word] = std::vector<int>(1, page);
        }
    }

    for (std::map<std::string, std::vector<int> >::iterator bookindex = BookIndex.begin(); bookindex != BookIndex.end(); ++bookindex) {
        std::cout << (*bookindex).first << std::endl;
        std::sort((*bookindex).second.begin(), (*bookindex).second.end());
        
        for (int i = 0; i < static_cast<int>((*bookindex).second.size()); ++i) {
            std::cout << (i == 0 ? "" : " " ) <<(* bookindex).second[i];
        }
        
        std::cout << std::endl;
        
    }

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  string s;
  int p;
  multimap<string, int> mm;
  while(cin>>s>>p) {
    mm.insert(make_pair(s,p));
  }
  string mae;
  int f = 0;
  FOR(it, mm) {
    string ima = (*it).first;
    vector<int> v;
    REP(i,mm.count(ima)) {
      v.push_back((*(it++)).second);
    }
    it--;
    sort(ALL(v));
    cout << ima << endl;
    REP(i,v.size()) {
      if (i) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
}

C++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1001
#define _MAX 100
#define HO 6
int main(void)
{
	char str[MAX];
	string word[_MAX];
	int pa[_MAX], rank[_MAX], cou, a;
	for (cou = 0; scanf_s("%s %d", str, &pa[cou]) != EOF;++cou) {
		string wo(str);
		word[cou] = wo;
		rank[cou] = cou;
	}
	for (int i = 0; i < cou; ++i) {
		for (int j = cou - 1; j > i; --j) {
			if (word[rank[j]] <= word[rank[j - 1]]) {
				if (word[rank[j]] == word[rank[j - 1]]) {
					if (pa[rank[j]] < pa[rank[j - 1]]) {
						a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
					}
				}
				else {
					a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
				}
			}
		}
	}
	for (int i = 0; i < cou; ++i) {
		if(i == 0 || word[rank[i - 1]] != word[rank[i]]) 
		cout << word[rank[i]] << "\n";
		if (i != 0 && word[rank[i - 1]] == word[rank[i]])
			printf(" ");
		printf("%d", pa[rank[i]]);
		if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]])
			printf("\n");
	}
	printf("\n");
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define SZ(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define MP make_pair
#define PB push_back
int main(){
	map<string ,vector<int> >ta;
	string s;
	int t;
	while(cin>>s>>t){
	ta[s].push_back(t);
	}
	map<string , vector<int> >::iterator it=ta.begin();
	for(;it!=ta.end();it++){
		cout<<(*it).first<<endl;
		vector<int>tmp=(*it).second;
		sort(tmp.begin(),tmp.end());
		for(int i=0;i<SZ(tmp);i++){
		cout<<tmp[i];
		(i==SZ(tmp)-1)?cout<<endl:cout<<" ";
		}
	}
	return 0;
}

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

int main(void)
{
	char words[100][30] = {"\0"};
	char temp1[30];
	int number[100] = {0};
	int temp2;
	int i, j, k, n, m, t;

	i = 0;
	while (scanf("%s %d*c", words[i], &number[i]) != EOF)
		i++;

	for (k = 0; k < 99; k++)
		for (i = 0; i < 100; i++)
			if (words[i + 1][0] != 0)
				for (j = 0; j < 30; j++)
					if (words[i][j] > words[i+1][j])
					{
						strcpy(temp1, words[i]);
					    strcpy(words[i], words[i+1]);
					    strcpy(words[i+1], temp1);

					    temp2 = number[i];
						number[i] = number[i+1];
						number[i+1] = temp2;

					    break;
					}
					else if (words[i][j] == words[i+1][j])
						continue;
					else
						break;
			else
				break;

	for (i = 0; i < 100; i++)
	{
		if (words[i][0] == NULL)
			break;
		if (strcmp(words[i], words[i+1]) != 0)
		{
			printf("%s\n", words[i]);
			printf("%d\n", number[i]);
		}
		else
		{
			for (n = 0; strcmp(words[i+n], words[i+n+1]) == 0; n++)
				;
			printf("%s\n", words[i]);

			for (t = 0; t < n; t++)
				for (m = 0; m < n; m++)
					if (number[i+m] > number[i+m+1])
					{
						temp2 = number[i+m];
						number[i+m] = number[i+m+1];
						number[i+m+1] = temp2;
					}

			for (m = 0; m <= n; m++)
			{
				printf("%d", number[i+m]);
				if (m == n)
					printf("\n");
				else
					printf(" ");
			}

			i += n;
		}
	}

	return 0;
}