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 _USE_MATH_DEFINES
using namespace std;
 
 
#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define rjm	rep(j,m)


#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}


#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define INF bit(60)

typedef pair<li, li> PI;

vector<pair<string, li>> book;

int main(int argc, char *argv[]){
	string s;
	li page;
	while(cin>>s){
		if(s=="hogehogehogehogehogehogehogehogehogehoge")break;
		cin>>page;
		book.pb({s, page});
	}
	sort(allof(book));

	string prev="";
	foreach(it, book){
		if(it->F!=prev){
			prev=it->F;
			cout<<endl;
			cout<<prev<<endl;
		}
		cout<<it->S;
		vector<pair<string, li>>::iterator next=it;
		next++;
		if(next!=book.end() && next->F==it->F)cout<<" ";
	}
	puts("");


	return 0;
}

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

int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,!std::cin.eof()){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::sort((*m_it).second.begin(),(*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while(v_it!=(*m_it).second.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==(*m_it).second.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	map<string, vector<int>>l;
	vector<string>str;
	while (!cin.eof()){
		string s;
		int n;
		cin >> s >> n;
		l[s].push_back(n);
		sort(l[s].begin(), l[s].end());
		if (find(str.begin(), str.end(), s) == str.end()) {
			str.push_back(s);
		}
	}
	sort(str.begin(), str.end());
	for (string i : str){
		cout << i << endl;
		for (int j = 0; j < l[i].size(); j++){
			cout << l[i][j];
			if (j != l[i].size() - 1)cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    map<string, vector<int> > m;
    string str; int n;
    while(cin >> str >> n){
        m[str].pb(n);
    }
    map<string, vector<int> >::iterator it = m.begin();
    for(; it != m.end(); it++){
        cout << (*it).first << endl;
        rep(i, (*it).second.size()) cout << (i?" ":"") << (*it).second[i];
        cout << 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 <algorithm>
#define N 100
using namespace std;
struct data{
  string str;
  int n;
  bool operator<(const data & right)const{
    if(str!=right.str) return str<right.str;
    return n<right.n;
  }
};
int main(){
  int i=0;
  struct data d[N];
  while(1){
    cin >> d[i].str >> d[i].n;
    if(d[i].str=="") break;
    i++;
  }
  sort(d,d+i);
  cout << d[0].str << endl << d[0].n;
  for(int j=1;j<i;j++){
    if(d[j].str==d[j-1].str) cout << ' ' << d[j].n;
    else cout << endl << d[j].str << endl << d[j].n;
  }
  cout << endl;
  return 0;
}

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

using P = pair<string, int>;

int main()
{
	P p[100];
	int i = 0;
	while (cin >> p[i].first >> p[i].second) i++;
	int n = i;

	sort(p, p + n);
	for (int i = 0; i < n; i++)
	{
		cout << p[i].first << endl << p[i].second;
		while (p[i].first == p[i + 1].first)
		{
			i++;
			cout << ' ' << p[i].second;
		}
		cout << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;main(){int n;string s;map<string,set<int> >z;map<string,set<int> >::iterator q;set<int>::iterator x;while(cin>>s>>n)z[s].insert(n);for(q=z.begin();q!=z.end();cout<<endl){cout<<(s=q++->first)<<endl;for(x=z[s].begin(),n=0;x!=z[s].end();cout<<*x++)if(n++)cout<<" ";}return 0;}

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