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 <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct index{
	string s;
	int p;
	bool operator<(const index &right) const{
		return right.s != s ? right.s > s :right.p > p;
	}

};
int main() {
	vector<index> book;
	string s;
	int n;
	while (cin >> s >> n)
		book.push_back({ s, n });
	SORT(book);
	s = "";
	REP(i, book.size()){
		if (book[i].s != s){
			if (i != 0)cout << endl;
			cout << book[i].s << endl;
			cout << book[i].p;
		}
		else{
			cout << ' ' << book[i].p;
		}
		s = book[i].s;
	}
	cout << endl;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

typedef pair<string, int> psi;

signed main() {
    string s; int n;
    vector<psi> vs;
    while(cin >> s >> n) {
        cin.ignore();
        vs.push_back(make_pair(s, n));
    }
    sort(vs.begin(), vs.end());
    string prev = "A";
    rep(i,0,vs.size()) {
        if(prev != vs[i].first) {
            if(prev != "A") cout << endl;
            cout << vs[i].first << endl;
            printf("%lld", vs[i].second);
            prev = vs[i].first;
        }
        else printf(" %lld", vs[i].second);
    }
    return 0;
}

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

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

using namespace std;

vector<string> split(const string &str, char delim)
{
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos)
  {
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

int main()
{
	string f[101];
	map<string,string> m;

	string s,n;
	vector<string> res;
	while(cin >> s)
	{
		cin >> n;
		m[s] += n + " ";

		vector<string>::iterator ite = find(res.begin(),res.end(),s);
		if(ite == res.end())
		{
			res.push_back(s);
		}
	}

	sort(res.begin(),res.end());

	rep(i,res.size())
	{
		cout << res[i] << endl;
		m[res[i]] = m[res[i]].substr(0,m[res[i]].size()-1);
		vector<string> _s = split(m[res[i]],' ');
		vector<int> v;
		rep(j,_s.size())
		{
			v.push_back(atoi(_s[j].c_str()));
		}

		sort(v.begin(),v.end());		
		
		rep(j,v.size())
		{
			if(j == _s.size()-1)
			{
				cout << v[j] << endl;
			}
			else
			{
				cout << v[j] << " ";
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
typedef pair<string,int> P;
int main(){
  P in;
  vector<P> n;
  while(cin >> in.first >> in.second){
    n.push_back(in);
  }
  sort(n.begin(),n.end());
  
  string tmp="omanko";
  for(int i=0;i<(int)n.size();i++){
    if( tmp != n[i].first ){
      if(i!=0) cout << endl;
      tmp = n[i].first;
      cout << n[i].first << endl;
      cout << n[i].second;
    } else{
      cout << " "<< n[i].second;
    }
  }
  cout << endl;
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	map< string, map<int,int> > table;
	string word;
	int n;
	while(cin>>word>>n){
		table[word][n]++;
	}
	for(map<string, map<int,int> >::iterator it = table.begin();it!=table.end();++it){
		cout<<it->first<<endl;
		map<int,int> w = it->second;
		for(map<int,int>::iterator it2 = w.begin();it2!=w.end();++it2){
			cout<<it2->first<<" ";
		}
		cout<<endl;
	
	}
	return 0;		
}

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

using namespace std;

int main(void){

	string index;
	int page;
	map<string,set<int> >dic;
	
	while(cin >> index >> page)
		dic[index].insert(page);
	
	 map<string,set<int> >::iterator it = dic.begin();
    for(;it != dic.end();it++){
        cout << it->first << endl;
    	
        set<int>::iterator its = (it->second).begin();
    	
        while(its != (it->second).end()){
            cout << *its;
        	if(++its != (it->second).end())cout << " ";
        	else cout << endl;
        }
    }
	
return 0;
}