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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	string s;
	map<int, string> table;
	vs name;
	vi page;

	while(cin >> s) {
		int p;
		cin >> p;
		name.push_back(s);
		page.push_back(p);
		table[p] = s;
	}

	sort(ALL(name));
	sort(ALL(page));
	
	set<string> names;
	REP(i, name.size()) {
		names.insert(name[i]);
	}

	set<string>::iterator it = names.begin();
	while(it != names.end()) {
		cout << *it << endl;
		REP(i, page.size()) {
			if(table[page[i]] == *it) {
				cout << page[i] << " ";
			}
		}
		cout << endl;
		++it;
	}

	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];
			if(j!=Books[i].page.size()){
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}

	return 0;
}

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

typedef pair<string,int> P;

int main(){
  string str;
  int page,cnt=0;
  vector<P> v;

  while(cin >> str >> page){
    v.push_back(P(str,page));
    cnt++;
  }

  sort(v.begin(),v.end());
  for(int i = 0 ; i < cnt; i++){
    if(i==0){
      cout << v[i].first << endl;
      cout << v[i].second;
      continue;
    }

    if(v[i].first == v[i-1].first && v[i].second!=v[i-1].second){
      cout << ' ' << v[i].second;
      continue;
    }
    else cout << endl;

    cout << v[i].first << endl;
    cout << v[i].second;
    }

  return 0;
}

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

int main(){
  typedef struct {
    char s[31];
    int a;
  } book;
  
  book b[100];
  int i=0;
  while(scanf("%s %d", b[i].s, &b[i].a) != EOF){
    i++;
  }
  
  int j,k;
  for(j=0;j<i-1;j++){
    for(k=0;k<i-1;k++){
      if(strcmp(b[k].s, b[k+1].s)>0)
	{int p;char q[31];
	  p=b[k].a;b[k].a=b[k+1].a;b[k+1].a=p;
	  strcpy(q,b[k].s);strcpy(b[k].s,b[k+1].s);strcpy(b[k+1].s,q);
	}
    }
  }


  for(j=0;j<i-1;j++){
    for(k=0;k<i-1;k++){
      if(strcmp(b[k].s, b[k+1].s)==0){
	if(b[k].a > b[k+1].a){
	  int p;
	  p=b[k].a;b[k].a=b[k+1].a;b[k+1].a=p;
	}
      }
    }
  }

  printf("%s \n%d", b[0].s, b[0].a);
  for(j=1;j<i;j++){
    if(strcmp(b[j].s, b[j-1].s) != 0){
      printf("\n");
      printf("%s \n%d ", b[j].s, b[j].a);
    }
    else{
      printf("%d ", b[j].a);
    }
  }
  printf("\n");

  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct index{
	string s;
	int p;
	bool operator<(const index &right) const{
		return right.s != s ? right.s > s :right.p > p;
	}

};
int main() {
	vector<index> book;
	string s;
	int n;
	while (cin >> s >> n)
		book.push_back({ s, n });
	SORT(book);
	s = "";
	REP(i, book.size()){
		if (book[i].s != s){
			if (i != 0)cout << endl;
			cout << book[i].s << endl;
			cout << book[i].p;
		}
		else{
			cout << ' ' << book[i].p;
		}
		s = book[i].s;
	}
	cout << endl;
}

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

int main()
{
	map<string, vector<int>>s;
	string a; int b;
	cin >> a >> b;
	vector<int>r(0);
	s.insert(pair<string,vector<int>>(a,r));
	s[a].push_back(b);
	while (1) {
		cin >> a >> b;
		if (cin.fail())break;
		for (auto c = s.begin(); c != s.end();c++) {
			if (a == c->first) {  c->second.push_back(b); break;}
			auto d = c;
			d++;
			if (d == s.end()) { vector<int>r(0); s.insert(pair<string, vector<int>>(a, r));  s[a].push_back(b); break; }
		}
	}
	for (auto e = s.begin(); e != s.end(); e++) {
		sort(e->second.begin(), e->second.end());
		cout << e->first << endl;
		for (int f : e->second) {
			cout << f << " ";
		}
		cout << "\b" << endl;
	}
}