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<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[j]!="zzzzzzz"&&str[num]>str[j])num=j;
        }
        cout<<str[num]<<endl;
        str[num]="zzzzzzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num]-1;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 <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
typedef pair<string, int> psi;

int main(){
	vector<psi> words;
	while(!cin.eof()){
		psi entry;
		cin >> entry.first >> entry.second;
		words.push_back(entry);
	}
	sort(words.begin(), words.end());
	string word = "";
	for(int i = 1; i < words.size(); ++i){
		if(words[i].first != word){
			if(word != ""){ cout << endl; }
			word = words[i].first;
			cout << word << endl;
		}
		cout << words[i].second << " ";
	}
	cout << endl;
	return 0;
}

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

using namespace std;

int main(){
    map<string,set<int> >m;
    set<string>s;
    string w;
    int p;
    while(cin>>w>>p){
        m[w].insert(p);
        s.insert(w);
    }
    set<int>::iterator it;
    set<string>::iterator st;
    for (st = s.begin(); st != s.end(); ++st){
        cout<<*st<<endl;
        it = m[*st].begin();
        if(m[*st].size()>1)
            for (; it != prev(m[*st].end(), 1); ++it)
                cout<<*it<<" ";
        cout<<*it<<endl;
    }
}

C++: #include<map>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	map < string, vector<int> > p;
	string s;
	int page;
	while (cin >> s >> page){
		p[s].push_back(page);
	}

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

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

int printIndex(){
    int number=0;
    string word;
    map<string,list<int> > index;
    
    while(!(cin>>word>>number).eof()){
        index[word].push_back(number);
        
    }
    
    map<string, list<int> >::iterator it = index.begin();
    while(it != index.end()){
        it->second.sort();
        list<int>::iterator ite = it->second.begin();
        cout << it->first << endl;
        while(ite!=it->second.end()){
            cout << *ite;
            ite++;
            if(ite!=it->second.end()) cout<<" ";
        }
        cout << endl;
        it++;
    }
}

int main(){
    printIndex();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

int page;
string word;
map<string, VI> mp;

int main() {
	while ( !!( cin >> word >> page ) ) {
		mp[ word ].push_back( page );
	}
	for( auto it = mp.begin(); it != mp.end(); ++it ) {
		printf( "%s\n", it->first.c_str() );
		VI pages = it->second;
		sort( pages.begin(), pages.end() );
		for ( int i = 0; i < pages.size() - 1; i++ ) {
			printf( "%d ", pages[ i ] );
		}
		printf( "%d\n", pages[ pages.size() - 1 ] );
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	string set;
	int num;

	vector<string>namelist;
	map<string,int>P;
	map<string,int>count;

	int numberlist[1000][101]={};
	int i=0,j=0,k=0,l=0;

	while(cin >> set >> num)
	{
		if(!P[set])
		{
			i++;
			namelist.push_back(set);
			P[set]=i;
		}
		numberlist[P[set]][count[set]]=num;
		count[set]++;
	}

	for(j=0;j<i;j++)
	{

		for(k=j;k<i;k++)
		{
			if(namelist[j]>namelist[k])
			{
				swap(namelist[j],namelist[k]);
			}
		}
	}
	for(j=0;j<i;j++)
	{
		for(k=0;k<count[namelist[j]];k++)
		{
			for(l=k;l<count[namelist[j]];l++)
			{
				if(numberlist[P[namelist[j]]][k]>numberlist[P[namelist[j]]][l])
					swap(numberlist[P[namelist[j]]][k],numberlist[P[namelist[j]]][l]);
			}
		}
	}

	for(j=0;j<i;j++)
	{
		cout << namelist[j] << endl;
		for(k=0;k<count[namelist[j]];k++)
		{
			cout << numberlist[P[namelist[j]]][k];
			if(k!=count[namelist[j]]-1)cout << " ";
		}
		cout << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;pair<string,int> a[];int main(){int t=0,g,i;while(cin>>a[t].first>>a[t].second)t++;sort(a,a+t);string f,b=a[0].first;cout<<b<<endl<<a[0].second;for(i=1;i<t;i++){bool n=0;f=a[i].first,g=a[i].second;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}