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 <stdio.h>
#include <iostream>
#include <list>
#include <map>
#include <stdlib.h>

using namespace std;

int main(void)
{
	list<string> strList;
	map<string, list<int> > pages;
	char buf[256];
	char word[256];
	int i;
	
	while (fgets(buf, 256, stdin) != NULL){
		for (i = 0; buf[i] != ' '; i++){
			word[i] = buf[i];
		}
		word[i] = '\0';
		i++;
		strList.push_back(word);
		pages[strList.back()].push_back(atoi(&buf[i]));
	}
	
	strList.sort();
	strList.unique();
	list<string>::iterator it;
	for (it = strList.begin(); it != strList.end(); it++){
		pages[*it].sort();
		list<int>::iterator itt;
		printf("%s\n", it->c_str());
		itt = pages[*it].begin();
		printf("%d", *itt);
		itt++;
		for (; itt != pages[*it].end(); itt++){
			printf(" %d", *itt);
		}
		cout << endl;
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num,page[1000][100]={},nu[1000]={};
    memset(nu,0,sizeof(nu));
    string str[1000],s;
    while(cin>>s>>num){
        for(int i=0;i<sen;i++){
            if(str[i]==s){
                nu[i]++;
                page[i][nu[i]]=num;
                num=0;
                break;
            }
        }
        if(num!=0){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    for(int i=0;i<sen;i++){
        for(int j=0;j<sen;j++)if(str[num]>str[j])num=j;
        cout<<str[num]<<endl;
        str[num]="zzzzzzzzzzzzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num];k>j;k--){
                if(page[num][k]<page[num][k-1]){
                    int kawa=page[num][k-1];
                    page[num][k-1]=page[num][k];
                    page[num][k]=kawa;
                }
            }
        }
        cout<<page[num][0];
        for(int j=1;j<=nu[num];j++)cout<<" "<<page[num][j];
        cout<<endl;
    }
}

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

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

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++: #pragma warning(disable:4996)
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;

int main(){
	string word;
	int page;
	map<string, set<int>> indexs;
	while (cin >> word >> page){
		indexs[word].insert(page);
	}
	for (auto index : indexs){
		cout << index.first << endl;
		for (auto page_a : index.second){
			cout << page_a<<" ";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;

string s[3]={"HIT","HOMERUN","OUT"};


int main(){
	map<string,vi> m;
	string s;
	int a;
	while(cin>>s>>a){
		m[s].pb(a);
	}
	for(map<string,vi>::iterator it=m.begin(); it!=m.end(); it++){
		bool f=false;
		cout<<it->fi<<endl;
		sort(all(it->se));
		for(int i=0; i<it->se.size(); i++){
			if(f)cout<<" ";
			cout<<it->se[i];
			f=true;
		}
		cout<<endl;
	}
}

C++: #include<iostream>
#pragma warning(disable:4786)
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	while(getline(cin, a)){
		string b, h = "";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k << endl;
		vector<int>::iterator ite = d[k].begin();
		for(ite=d[k].begin();ite!=d[k].end();++ite) {
			if (ite == d[k].begin())
				cout << *ite;
			else
				cout << " " << *ite;
		}
		cout << "\n";
		t++;
	}
}

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

using namespace std;

char returnc(char c){
  if('a'<=c && c<='z'){
    if(c=='z')return 'a';
    return ++c;
  }
  return c;
}
int main(void){
  string s;
  int n;
  vector<string> ss;
  vector<vector<int> > nn;
  while(cin>>s>>n){
    if(ss.empty()){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
    }
    bool ok = true;
    for(int i = 0 ; i < ss.size() ; i ++){
      if(ss[i] == s){
	nn[i].push_back(n);
	ok = false;
      }
    }
    if(ok){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      
    }
  }
  for(int i = ss.size() - 1 ; i >= 0 ; i --){
    for(int j = 0 ; j < i ; j ++){
      if(ss[i] < ss[j]){
	string w = ss[i];
	ss[i] = ss[j];
	ss[j] = s;
	vector<int> ws = nn[i];
	nn[i] = nn[j];
	nn[j] = ws;
      }
    }
  }
  for(int i = 0 ; i < ss.size() ; i ++){
    cout<<ss[i]<<endl;
    for(int j = 0 ; j < nn[i].size()-1 ; j ++){
      cout<<nn[i][j]<<" ";
    }
    cout<<nn[i][nn[i].size() - 1 ]<<endl;
  }
}

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

using namespace std;

struct P {
	string a;
	int b;
};

int main() {
	string a;
	int b;
	P retu[110];
	int i = 0;
	while (cin >> a >> b) {
		P p;
		p.a = a;
		p.b = b;
		retu[i] = p;
		i++;
	}
	for (int j = i; j > 0; j--) {
		for (int k = 0; k < j-1; k++) {
			if (retu[k].a > retu[k+1].a) {
				swap(retu[k], retu[k+1]);
			} else if (retu[k].a == retu[k+1].a) {
				if (retu[k].b > retu[k+1].b) {
					swap(retu[k], retu[k+1]);
				}
			}
		}
	}
	for (int j = 0; j < i; j++) {
		if (j == 0) {
			cout << retu[0].a << endl << retu[0].b;
		} else {
			if (retu[j].a == retu[j-1].a) {
				cout << ' ' << retu[j].b;
			} else {
				cout << endl << retu[j].a << endl << retu[j].b;
			}
		}
	}
	cout << endl;
	return 0;
}