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;
#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( map<string, VI>::iterator 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<stdio.h>
#include<string.h>

#include<stdio.h>

int main(){
  typedef struct {
    char s[31];
    int a;
  } book;
  
  book b[100];
  int i=0;
  while(scanf("%s %d", b[i].s, &b[i].a) != EOF){
    i++;
  }
  
  int j,k;
  for(j=0;j<i-1;j++){
    for(k=0;k<i-1;k++){
      if(strcmp(b[k].s, b[k+1].s)>0)
	{int p;char q[31];
	  p=b[k].a;b[k].a=b[k+1].a;b[k+1].a=p;
	  strcpy(q,b[k].s);strcpy(b[k].s,b[k+1].s);strcpy(b[k+1].s,q);
	}
    }
  }


  for(j=0;j<i-1;j++){
    for(k=0;k<i-1;k++){
      if(strcmp(b[k].s, b[k+1].s)==0){
	if(b[k].a > b[k+1].a){
	  int p;
	  p=b[k].a;b[k].a=b[k+1].a;b[k+1].a=p;
	}
      }
    }
  }


  for(j=0;j<i;j++){
    printf("%s %d\n", b[j].s, b[j].a);
  }
  return 0;
}

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

int main(){
  map<string,vector<int> >m;
  string s;int x,f;
  for(;cin>>s>>x;)
    m[s].push_back(x);
  map<string,vector<int> >::iterator it=m.begin();
  for(;it!=m.end();it++){
    cout<<(*it).first<<endl;
    vector<int>v=(*it).second;
    sort(v.begin(),v.end());
    for(f=0;f<v.size();f++){
      if(f)cout<<' ';
      cout<<v[f];
    }
    cout<<endl;
  }
}

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

using namespace std;

int main()
{
	vector< pair<string, int> > data;

	string str;
	int a;
	while (cin >> str >> a) {
		data.push_back(pair<string, int>(str, a));
    }
	sort(data.begin(), data.end());
	
	pair<string, int> preData;
	for (pair<string, int> e: data) {
		if (preData.first == e.first) {
			cout << " " << e.second;
		} else {
			cout << endl << e.first << endl << e.second;
		}
		preData = e;
	}

    return 0;
}

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

using namespace std;

int main(){
    string inWord, num;
    map<string, string> word;
    map<string, string>::iterator itr;
    
    while(cin >> inWord >> " " >> num){
        if(!word[inWord].empty()){
            word[inWord] = num;
        }else{
            word[inWord] += " " + num;
        }
    }
    
    sort(word.begin(), word.end());
    
    for(itr = word.begin(); itr != word.end(); itr++){
        cout << itr -> first << endl;
        cout << itr -> secound << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int cnt;
pair<string,int> t[1000];
int main(){
  for(cnt=0;cin>>t[cnt].first>>t[cnt].second;cnt++);
  sort(t,t+cnt);
  cout<<t[0].first<<endl<<t[0].second;
  for(int i=1;i<cnt;i++){
    if(t[i-1].first==t[i].first)cout<<' '<<t[i].second;
    else cout<<endl<<t[i].first<<endl<<t[i].second;
  }
  cout<<endl;
  return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	string str;
	vector<pair<string,int>>sp;
	int num;
	while(cin>>str>>num){
		sp.PB(MP(str,num));
	}
	bool c=false;
	SORT(sp);
	REP(i,SZ(sp)){
		if(!c)cout<<sp[i].first<<endl;
		if(i!=SZ(sp)-1&&sp[i].first==sp[i+1].first){
			cout<<sp[i].second<<" ";
			c=true;
		}else{
			c=false;
			cout<<sp[i].second<<endl;
		}
		
	}
	return 0;
}