Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dictionary := make(map[string][]int)

	for {
		var word string
		var page int
		fmt.Scanf("%s %d", &word, &page)

		if word == "" || page == 0 {
			break
		}

		pages := dictionary[word]
		pages = append(pages, page)
		dictionary[word] = pages
	}

	words := make([]string, 0)
	for i := range dictionary {
		words = append(words, i)
	}

	sort.Strings(words)

	for _, v := range words {
		sort.Ints(dictionary[v])
		fmt.Println(v)
		for i, page := range dictionary[v] {
			if i == len(dictionary[v])-1 {
				fmt.Printf("%d\n", page)
			} else {
				fmt.Printf("%d ", page)
			}
		}
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<string, int>P;

int main() {
	vector<P>v;
	string s; int n;
	while (cin >> s >> n) {
		v.push_back(P(s, n));
	}
	sort(v.begin(), v.end(), [](P a, P b) {return a.second < b.second; });
	stable_sort(v.begin(), v.end());
	rep(i, v.size()) {
		if (i&&v[i - 1].first == v[i].first) {
			cout << ' ' << v[i].second;
			continue;
		}
		if (i)cout << endl;
		cout << v[i].first << endl << v[i].second;
	}
	cout << endl;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <set>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>


#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;

map< string, vector<int> > book;

void solve()
{
	EACH(i, book)
	{
		cout << i->first << endl;
		
		FOR(j, 0, i->second.size()-1)
		{	
			cout << i->second[j];
			cout <<	' ';
		}
		
		cout << i->second[i->second.size()-1] << endl;
	}
	
	return;
}


int main()
{
	string str;
	int pg;
	
	while(cin >> str, !cin.eof())
	{
		cin >> pg;
		book[str].push_back(pg);
		
		sort(ALL(book[str]));
	}
	
	solve();
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<pair<string,int>> str(1000);
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int count = 0;
    int c_n = 0;
    while (cin >> str[count].first >> str[count].second) {
        count++;
    }
    cout << endl;
    sort(str.begin(), str.begin() + count);
    cout << str[0].first << endl;
    cout << str[0].second;
    for (int i = 1; i < count; i++) {
        if (str[i].first != str[i-1].first) {
            cout << endl << str[i].first << endl;           
        }
        cout << str[i].second << " ";
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string name[111], a;
	int na, kazu[111], date[111][111], b;
	for (int i = 1; i <= 101; i++) {
		kazu[i] = 0;
	}
	na = 0;
	while (cin >> a >> b) {
		for (int i = 1; i <= na; i++) {
			if (name[i] == a) {
				kazu[i] = kazu[i] + 1;
				date[i][kazu[i]] = b;
				goto a;
			}
		}
		na = na + 1;
		name[na] = a;
		kazu[na] = 1;
		date[na][kazu[na]] = b;
	a:;
	}
	string aa;
	int bb,min,mi;
	for (int i = 1; i <= na; i++) {
		aa = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz";
		for (int z = 1; z <= na; z++) {
			if (aa >= name[z]) {
				aa = name[z];
				bb = z;
			}
		}
		cout << aa << endl;
		name[bb] = "zzzzzzzzzzzzzzzzzzzzzzzz";
		for (int z = 1; z <= kazu[bb]; z++) {
			min = 9999;
			for (int m = 1; m <= kazu[bb]; m++) {
				if (date[bb][m] <= min) {
					min = date[bb][m];
					mi = m;
				}
			}
			cout << min << " ";
			date[bb][mi] = 9999;
		}
		cout << endl;
	}
}

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

using namespace std;

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

map<string,vector<int>> index;
int main(){
    string s; int p;
    while(cin>>s>>p) index[s].push_back(p);
    for(auto &w:index){
        cout<<w.first<<endl;
        sort(w.second.begin(), w.second.end());
        rep(i,w.second.size()){
            cout<<w.second[i]<<(i==w.second.size()-1 ? '\n' : ' ');
        }
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

vector< PS > vs;
string s;
ll n;

int main(){
	while (cin >> s >> n){
		vs.push_back(PS(s, n));
	}
	sort(ALL(vs));
	REP(i, vs.size()){
		if (s != vs[i].first||i==0){
			if(i!=0)cout << endl;
			s = vs[i].first;
			cout << vs[i].first << endl;
			cout << vs[i].second << " ";
		}
		else{
			cout << vs[i].second << " ";
		}
	}
	cout << endl;
}

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

class package
{
public:
	string word;
	int page;
	package(string _word, int _page)
	{
		word = _word;
		page = _page;
	}

};
bool compare(const package & left, const package & right)
{
	if(left.word < right.word)
	{
		return true;
	}
	if(left.word == right.word && left.page <= right.page)
	{
		return true;
	}
	return false;
}
int main()
{

	vector<package> book;
	
	while(1)
	{
		string str = "";
		int page;
		cin >> str;
		if(str == "")
		{
			break;
		}
		cin >> page;
		package index(str, page);
		book.push_back(index);
	}

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

	string lastWord = book[0].word;
	cout << book[0].word << endl;
	cout << book[0].page;

	for(int i = 1; i < book.size(); i++)
	{
		if(lastWord == book[i].word)
		{
			cout << " " << book[i].page;
			
		}
		else
		{
			cout << endl;
			cout << book[i].word << endl;
			cout << book[i].page;
			lastWord = book[i].word;
		}
	}
	


}

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

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

    string word;
    int page;

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

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

    return 0;
}

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