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 <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

pair<string,int> dic[1010];

int main(void){
	int n=0;
	while(true){
		string key;
		int num;
		cin >> key >> num;
		if(cin.eof())
			break;
		dic[n].first=key;
		dic[n++].second=num;
	}
	sort(dic,dic+n);
	string prev="";
	rep(i,n){
		if(prev==""){
			cout << dic[i].first << endl;
			cout << dic[i].second;
		}else if(prev==dic[i].first){
			cout << " " << dic[i].second;
		}else{
			cout << endl;
			cout << dic[i].first << endl;
			cout << dic[i].second;
		}
		prev=dic[i].first;
	}
	return 0;
}

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

int main()
{
	int p,i;
	string s;
	map<string,vector<int> > dt;
	while(cin >> s >> p)
	{
		dt[s].push_back(p);
	}

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

	return 0;
}

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<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main()
{
	multimap<string,int> ans;
	string in; int num;
	while(cin>>in>>num) 
	{
		ans.insert(multimap<string,int>::value_type(in,num));
	}

	multimap<string,int>::iterator it=ans.begin();
	while(1) 
	{
		int cnt=ans.count((*it).first);
		cout<<(*it).first<<endl;
		bool f=false;
		vector<int> nums(0,0);
		while(cnt--) 
		{
			//cout<<(*it).second<<endl;
			nums.push_back((*it).second);
			it++;
		}
		sort(nums.begin(),nums.end());
		for(int i = 0; i < nums.size(); ++i)
		{
			if(f) cout<<" ";
			cout<<nums[i];
			f=true;
		}
		cout<<endl;
		if(it==ans.end()) break;
	}
  return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "<debug " << x << endl;
#define inf 5000
using namespace std;

void sort(int x[102]){
    rep(i,102){
        rep(j,102){
            bool c = true;
            if(x[j] > x[j + 1]){
                int temp = x[j];
                x[j] = x[j + 1];
                x[j + 1] = temp;
                c = false;
            }
            if(c) break;
        }
    }
}

int main(){
    string word;
    int page, pageList[102][102], index = 1;
    rep(i,102) rep(j,102) pageList[i][j] = inf;
    map<string,int> info;

    while(cin >> word >> page){
        if(info[word] == 0){
            info[word] = index;
            index++;
        }
        int i = 0;
        while(true){
            if(pageList[ info[word] ][i] == inf){
                pageList[info[word]][i] = page;
                break;
            }
            i++;
        }
    }
    rep(i,102){
        sort(pageList[i]);
    }
    map<string, int>::iterator it;
    for(it = info.begin(); it != info.end(); it++){
        cout << it->first << endl;
        rep(i,102){
            if(pageList[ it->second ][i] != inf){
                if(i) cout << ' ';
                cout << pageList[ it->second ][i];
            }else break;
        }
        cout << endl;
    }
}

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

int main()
{
  map<string, vector<int> > m;
  set<string> name;
  string str;
  int ind;
  while (cin >> str >> ind) {
    m[str].push_back(ind);
    name.insert(str);
  }
  
  for (set<string>::iterator it = name.begin(); it != name.end(); it++) {
    cout << *it << endl;;

    sort(m[*it].begin(), m[*it].end());

    for (int j = 0; j < m[*it].size(); j++) {
      cout << m[*it][j];
      if (j != m[*it].size() - 1) {
	cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
    string word;
    int page;
    bmap words;
    while (cin >> word >> page) {
        if (words.find(word)==words.end()) {
            vector<int> pages;
            pages.push_back(page);
            words[word] = pages;
        } else {
            words[word].push_back(page);
        }
    }
    bmap::iterator it;
    for (it=words.begin(); it!=words.end(); it++) {
        sort((*it).second.begin(), (*it).second.end());
        cout << (*it).first << endl;
        for (int i=0; i<(*it).second.size()-1; i++) {
            cout << (*it).second[i] << " ";
        }
        cout << (*it).second[(*it).second.size()-1] << endl;
    }
}

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

map<string,set<int>> p;

int main()
{
    string str;
    int t;
    while (cin >> str >> t) p[str].insert(t);
    for (auto it = p.begin(); it != p.end(); it++) {
        auto s = it->second.bigen();
        cout << it->first  << endl << *s;
        for (++s; s != it->second.end(); s++)
            cout << " " << *s;
        cout << endl;
    }

    return 0;
}