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 <algorithm>
#include <cstring>
using namespace std;

struct dic{
	string s;
	int page[1001];
};

int comp(const void *a, const void *b){
if(((dic*)a)->s > ((dic*)b)->s) return 1;
else return -1;
}

int main(){
	int i,j,p,tail=0;
	string str;
	dic d[100];
	memset(d, 0, sizeof(d));
	while((cin >> str) != NULL){
		for(i=0;i<tail;i++){
			if(str == d[i].s){
				cin >> p;
				d[i].page[p]=1;
				break;
			}
		}
		if(i == tail){
			d[tail].s = str;
			cin >> p;
			d[tail].page[p]=1;
			tail++;
		}
	}

	qsort(&d,tail,sizeof(dic),comp);
	int f=0;
	for(i=0;i<tail;i++){
		f=0;
		cout << d[i].s << endl;
		for(j=0;j<1001;j++){
			if(d[i].page[j] == 1){
				if(f) cout << " " << j;
				else{ cout << j; f++;}
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

string char_to_str(char *c) {
	string ret = "";

	for (; *c; ++c)
		ret += *c;

	return ret;
}

int main() {
	map<string, vector<int> > m;
	vector<string> words;

	char word[50]; int page;
	while (scanf("%s%d\n", word, &page) != EOF) {
		string str = char_to_str(word);
		m[str].push_back(page);
		words.push_back(str);
	}

	sort( words.begin(), words.end() );
	words.erase( unique( words.begin(), words.end() ), words.end() );

	for (int i = 0; i < words.size(); ++i) {
		vector<int> v = m[words[i]];
		sort( v.begin(), v.end() );

		cout << words[i] << endl;
		for (int j = 0; j < v.size(); ++j) {
			cout << v[j];
			if (j+1 < v.size()) cout << " ";
		}
		cout << endl;
	}
}

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=-1;
            }
        }
        if(num!=-1){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    int kawa;
    for(int i=0;i<sen;i++){
        num=0;
        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>0;k--){
                if(page[num][k]<page[num][k-1]){
                    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 <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<t->second.end()-t->second.end();i++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num=0,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=-1;
            }
        }
        if(num!=-1){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    int kawa;
    for(int i=0;i<sen;i++){
        num=0;
        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>0;k--){
                if(page[num][k]<page[num][k-1]){
                    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 <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  map<string, vector<int> > in;

  string goku;
  int id;
  while( cin >> goku >> id ){
    in[goku].push_back(id);
  }
    for( map < string, vector<int> >::iterator it = in.begin() ; it != in.end() ; it++ ){

      cout << (*it).first << " ";
    vector <int>& go = (*it).second;
    sort(go.begin(),go.end());
    for(vector <int>::iterator  it_p = go.begin() ; it_p != go.end() ; it_p++ ){
      cout << (*it_p);
      if(it_p+1 != go.end() )cout << " ";
    }
    cout << endl;
    }

  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pair<string,int> > p;

int main() {
	string word;
	int page;
	while(cin>>word>>page){
		p.push_back(mp(word,page));
	}
	int i;
	pair<string,int> pp;
	pair<string,int> pre;
	pre.first="";
	bool f=true;
	for(i=0;i<p.size();i++){
		int j,k=0;
		pp=p[0];
		for(j=1;j<p.size()-i;j++){
			if(pp.first>p[j].first||pp.first==p[j].first&&pp.second>p[j].second){
				pp=p[j];
				k=j;
			}
		}
		if(pp.first!=pre.first){
			if(!f)cout<<endl;
			f=false;
			cout<<pp.first<<endl<<pp.second;
		}else{
			cout<<" "<<pp.second;
		}
		pre=pp;
		p[k]=p[p.size()-i-1];
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

int main(void){
  map<string, vector<int> > i;
  string str;
  int n;
  int j;

  while(cin >> str >> n){
	i[str].push_back(n);
  }

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