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<functional>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef pair<string,int> P;
int main(){
	string s,temp;
	int x;
	priority_queue<int,vector<int>,greater<int>()> que;
	multimap<string,int> box;
	while(cin>>s>>x,x)
		box.insert(P(s,x));
	box.insert(P("zzzzzzz",0));
	multimap<string,int>::iterator ite;
	for(ite=box.begin();ite->second!=0;){
		temp=ite->first;
		que.push(ite->second);
		ite++;
		while(ite->first==temp){
			que.push(ite->second);
			ite++;
		}
		cout<<temp<<endl;
		cout<<que.top();
		que.pop();
		while(!que.empty()){
			cout<<' '<<que.top();
			que.pop();
		}
		cout<<endl;
	}
	return 0;
}

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

static const int MAX_WORD_LEN = 30;
static const int MAX_PAGE_NUM = 1000;
static const int MAX_BOOK_NUM = 100;

static const int VOID_PAGE    = -1;

class BookIndex {
public:
  BookIndex() {}
  ~BookIndex() {}
  // ????????????????????°????????????
  void SetWord(string word_, int page_) {
    word_page.insert(M::value_type(word_, page_));
  }
  // ??¨??????????????????????????°?????????
  void PrintWords() {
    for (MIT it = word_page.begin(); it != word_page.end();) {
      cout << it->first << endl;
      int count = word_page.count(it->first);
      set<int> st;
      for (int i = 0; i < count; i++) {
        st.insert(it++->second);
      }
      set<int>::iterator st_it = st.begin();
      cout << *st_it++;
      for (; st_it != st.end();st_it++) {
        cout << " " << *st_it;
      }
      cout << endl;
    }
  }
private:
  typedef multimap<string, int> M;
  typedef M::iterator           MIT;
  M word_page;
};

int main() {
  BookIndex book;

  // ??\????????°
  string word;
  int    page;
  while (cin >> word) {
    cin >> page;
    book.SetWord(word, page);
  }
  book.PrintWords();
}

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

template< class T >
void exchange( T &a, T &b )
{
    T c  = a;
    a = b;
    b = c;
}

int main()
{
    string str, words[100];
    int p, d[100];

    int i = 0;
    while( cin >> str )
    {
        cin >> p;
        words[i] = str;
        d[i] = p;
        i++;
    }

    for( int j = 0; j < i - 1; j++ )
        for( int k = j + 1; k < i; k++ )
            if( words[j] > words[k] )
            {
                exchange( words[j], words[k] );
                exchange( d[j], d[k] );
            }

    for( int j = 0; j < i - 1; j++ )
        for( int k = j + 1; k < i; k++ )
            if( words[j] == words[k] && d[j] > d[k] )
                exchange( d[j], d[k] );

    cout << words[0] << endl << d[0];
    for( int j = 1; j < i; j++ )
        if( words[j-1] == words[j] )
            cout << " " << d[j];
        else
            cout << endl << words[j] << endl << d[j];
    
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;


int main()
{
    map<string,set<int> > m;
    string s;
    while(cin>>s)
    {
        int p;
        cin>>p;
        m[s].insert(p);
    }
    for(map<string,set<int> >::iterator it = m.begin();it!=m.end();it++)
    {
        cout<<(it->first)<<endl;
        bool first = true;
        for(set<int>::iterator it2 = it->second.begin();it2 != it->second.end();it2++)
        {
            cout<<(first?"":" ")<<(*it2);
            first=false;
        }
        cout<<endl;
    }
}

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

using namespace std;

int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page;

    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }

    for (auto& book : books){
        cout<<book.first<<endl;

        sort(book.second.begin(), book.second.end());

        for (const auto& page : book.second){
            cout<<page<<" ";
        }
        cout<<'\n';
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
pair<string,int> p;
vector<pair<string,int> > v;
while(cin>>p.first>>p.second){
v.push_back(make_pair(p.first,p.second));
}
sort(v.begin(),v.end());

cout<<v[0].first<<endl;
cout<<v[0].second;
string bef=v[0].first;
for (int i = 1; i < v.size(); ++i) {
    if(bef!=v[i].first){
    	cout<<endl;
    	cout<<v[i].first<<endl;
    	cout<<v[i].second;
    	bef=v[i].first;
    }else{
    	cout<<" "<<v[i].second;
    }
}
//cout<<endl;
}

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

int main() {
  map<string, vector<int> > M;
  string in;
  int page;
  while(cin>>in>>page) {
    if(M.find(in) == M.end())
      M[in] = vector<int>(1, page);
    else
      M[in].push_back(page);
  }

  map<string, vector<int> >::iterator it = M.begin();
  while(it != M.end()) {
    cout<<(*it).first<<endl;
    sort((*it).second.begin(), (*it).second.end());
    for(int i=0; i<(*it).second.size()-1; ++i)
      cout<<(*it).second[i]<<" ";
    cout<<(*it).second[(*it).second.size()-1]<<endl;
    it++;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long int lint;
typedef long long int llint;
#define rep(i, f, n) for (int (i) = (f); i < (n); i++)

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

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

  for (map<string, vector<int> >::iterator it = index.begin(); it != index.end(); ++it){
    cout << it->first << endl;
    vector<int>& pages = it->second;
    sort(pages.begin(), pages.end());
    for (int i = 0; i < pages.size(); i++){
      if (i != 0){
        cout << ' ';
      }
      cout << pages[i];
    }
    cout << endl;
  }
}

C++: #include<iostream>
#include<map>
#include<set>
#include<string>

std::map<std::string, std::set<int> > m;

int main()
{
	std::string s;
	int p;
	while( std::cin >> s >> p )
		m[s].insert( p );

	for( std::map<std::string, std::set<int> >::iterator it = m.begin(); it != m.end(); ++it )
	{
		std::cout << it->first << std::endl;

		std::set<int>& s = it->second;

		for( std::set<int>::iterator it2 = s.begin(); it2 != s.end(); ++it2 )
			( it2 == s.begin() ? std::cout : std::cout << " " ) << *it2;
	
		std::cout << std::endl;
	}

	return 0;
}