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;

int main()
{
    map<string, set<int> > m;
    string inp;
    int num;

    while (cin >> inp >> num) 
        m[inp].insert(num);

    map<string, set<int> >::iterator it = m.begin();
    while (it != m.end()) {
        cout << (*it).first << endl;
        set<int>::iterator it_in;
        for (it_in = (*it).second.begin(); it_in != (*it).second.end(); it_in++) {
            if(it_in != (*it).second.begin())
                cout << " ";
            cout << *it_in;
        }
        cout << endl;
        it++;
    }

    return 0;
}

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

int main(void) {
    map<string, vector<int>> hm;
    
    string name; int page;
    while(cin >> name >> page) {
        hm[name].push_back(page);
        //cout << "hm[" << name << "] = " << hm[name] << endl;
    }
    for(auto ite = hm.begin(); ite != hm.end(); ite++) {
        cout << ite->first << endl;
        sort(ite->second.begin(), ite->second.end());
        for(int r = 0; r < ite->second.size(); r++) {
            cout << ite->second[r];
            if(r == ite->second.size()-1) putchar('\n');
            else putchar(' ');
        }
    }
    return(0);
}

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

class tWord{
public:
	string word;
	vector<int> page;
	tWord( string w );
	bool operator <( const tWord& r ){
		return (strcmp(word.c_str(), r.word.c_str())<0);
	}
};
tWord::tWord( string w ){
	word = w;
	page.clear();
}

int main(){
	vector<tWord> words;
	string line;
	int n;
	char w[31];

	// input
	while(1){
		getline( cin, line );
		if( line.size()==0 ) break;
		sscanf(line.c_str(), "%s %d", w, &n);
		int i;
		for( i=0; i<words.size(); i++ ){
			if( words[i].word == w ){
				break;
			}
		}
		if( i == words.size() ){
			string ww = w;
			words.push_back(ww);
		}
		words[i].page.push_back(n);
	}

	// output
	sort( words.begin(), words.end() );
	for( int i=0; i<words.size(); i++ ){
		if( words[i].word != "" ){
			cout << words[i].word << endl;
			sort( words[i].page.begin(), words[i].page.end() );
			cout << words[i].page[0];
			for( int j=1; j<words[i].page.size(); j++ ){
				cout << " " << words[i].page[j];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int cnt;
pair<string,int> t[1000];
int main(){
  for(cnt=0;cin>>t[cnt].first>>t[cnt].second;cnt++);
  sort(t,t+cnt);
  cout<<t[0].first<<endl<<t[0].second;
  for(int i=1;i<cnt;i++){
    if(t[i-1].first==t[i].first)cout<<' '<<t[i].second;
    else cout<<endl<<t[i].first<<endl<<t[i].second;
  }
  cout<<endl;
  return 0;
}

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

using namespace std;

int main()
{
	map <string, vector<int> > book;
	char s[30];
	int n;
	
	while(scanf("%s %d", s, &n) != EOF){
		string str = s;
		book[str].push_back(n);
	}
#ifdef ONLINE_JUDGE
	for (const auto& kv : book){
		puts(kv.first.c_str());
		sort(kv.second.begin(), kv.second.end());
		for (int i = 0; i < (int)it->second.size(); i++){
			printf("%d%c", kv.second[i], " \n"[i == (int)kv.second.size() - 1]);
		}
	}
#else
	for (map<string, vector<int> >::iterator it = book.begin(); it != book.end(); ++it){
		printf("%s\n", it->first.c_str());
		sort(it->second.begin(), it->second.end());
		for (int i = 0; i < (int)it->second.size(); i++){
			printf("%d%c", it->second[i], " \n"[i == (int)it->second.size() - 1]);
		}
	}
#endif
	return(0);
}

C++: #include <iostream>
#include <string>
using namespace std;
struct dic{
	string str;
	int n;
};

int main(){
	string a,stmp;
	int b,d = 0,i,j,itmp;
	dic c[101];
	while(cin >> a >> b){
		c[d].str = a;
		c[d].n = b;
		++d;
	}
	for(i = 0;i < d;i++){
		for(j = d - 1;j > i;j--){
			if(c[i].str > c[j].str){
				stmp = c[j].str;
				c[j].str = c[i].str;
				c[i].str = stmp;
				itmp = c[j].n;
				c[j].n = c[i].n;
				c[i].n = itmp;
			}
		}
	}
	for(i = 0;i < d;i++){
		cout << c[i].str << endl;
		cout << c[i].n;
		while(c[i].str == c[i+1].str){
			++i;
			cout << " " << c[i].n;
		}
		cout << "\n";
	}
	return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair< string,int > p;

vector<p> book;

int main() {
  string s;
  int P;
  while(cin >> s >> P) {
    p temp;
    temp.first = s;
    temp.second = P;
    book.push_back(temp);
  }
  sort(book.begin(),book.end());
  int j=0;
  string now = "";
  for(int i=0;i<book.size();i++) {
    if(now != book[i].first) {
      if(i!=0) cout << endl;
      now = book[i].first;
      cout << now << endl;
    }


    cout << book[i].second << " ";


  }
}

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

using namespace std;

typedef map< string, set<int> > Dic;
Dic dic;

int main(){
  //map<string, int> dic;
  int num;
  string s;
  while(cin >> s >> num)
  {
    dic[s].insert(num);
  }
  
  for(Dic::iterator it = dic.begin() ; it != dic.end() ; it++)
  {
  	cout << it->first << endl;
  	for(set<int>::iterator set_it = it->second.begin() ; set_it != it->second.end() ; set_it++)
  	{
  		cout << *set_it << " ";
  	}
  	cout << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

string s;
int n;
vector<string> vs;
map<string,vi> M;

int main(){
	while(cin>>s>>n){
		M[s].push_back(n);
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end());
	vs.erase(unique(vs.begin(),vs.end()),vs.end());
	for(vector<string>::iterator i=vs.begin();i!=vs.end();i++){
		cout<<*i<<endl;
		sort(M[*i].begin(),M[*i].end());
		int S=M[*i].size()-1;
		for(int j=0;j<S;j++) cout<<M[*i][j]<<' ';
		cout<<M[*i][S]<<endl;
	}
}

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

int main() {
    map<string, set<int> > pagenumbers;

    string word;
    int page;

    while (cin >> word >> page) {
        pagenumbers[word].insert(page);
    }

    for (map<string, set<int> >::iterator it = pagenumbers.begin(); it != pagenumbers.end(); ++it) {
        cout << it->first << endl;
        for (set<int>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
            cout << *it2 << " ";
        }
        cout << endl;
    }

    return 0;
}