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>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator << (ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator << (ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator << (ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator << (ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}

map<string, vi> book;
string s;
int n;

int main()
{
  while(cin >> s >> n) book[s].pb(n);

  vrep(v, book){
    sort(ALL(v->second));
    cout << v->first << endl;
    cout << v->second << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num,page[1000][100]={},nu[1000]={};
    memset(nu,0,sizeof(nu));
    string str[1000],s;
    while(cin>>s>>num){
        for(int i=0;i<=sen;i++){
            if(str[i]==s){
                nu[i]++;
                page[i][nu[i]]=num;
                num=-1;
            }
        }
        if(num!=-1){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    int kawa;
    for(int i=0;i<sen;i++){
        num=0;
        for(int j=0;j<sen;j++)if(str[j]!="zzz"&&str[num]>str[j])num=j;
        cout<<str[num]<<endl;
        str[num]="zzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num];k>0;k--){
                if(page[num][k]<page[num][k-1]){
                    kawa=page[num][k-1];
                    page[num][k-1]=page[num][k];
                    page[num][k]=kawa;
                }
            }
        }
        cout<<page[num][0];
        for(int j=1;j<=nu[num];j++)cout<<" "<<page[num][j];
        cout<<endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<SIZE-1i++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
struct dic{
	string str;
	int n;
};

int main(){
	string a,stmp;
	int b,d = 0,i,j,itmp;
	dic c[101];
	while(cin >> a >> b){
		c[d].str = a;
		c[d].n = b;
		++d;
	}
	for(i = 0;i < d;i++){
		for(j = d - 1;j > i;j--){
			if(c[i].str > c[j].str){
				stmp = c[j].str;
				c[j].str = c[i].str;
				c[i].str = stmp;
				itmp = c[j].n;
				c[j].n = c[i].n;
				c[i].n = itmp;
			}
			else if(c[i].str == c[j].str){
				if(c[i].n > c[j].n){
					itmp = c[j].n;
					c[j].n = c[i].n;
					c[i].n = itmp;
				}
			}
		}
	}
	for(i = 0;i < d;i++){
		cout << c[i].str << endl;
		cout << c[i].n;
		while(c[i].str == c[i+1].str){
			++i;
			cout << " " << c[i].n;
		}
		cout << "\n";
	}
	return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page, page_count;

    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }

    for (auto& book : books){
        cout<<book.first<<endl;
        page_count=0;
        sort(book.second.begin(), book.second.end());
        for (int page : book.second){
            if (page_count) cout<<" "<<page;
            else cout<<page;
            page_count++;
        }
        cout<<'\n';
    }
    return 0;
}

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

using namespace std;

int main(void){
    map<string,set<int> > data;
    int n;
    string str;
    
    while(cin>>str>>n){
        data[str].insert(n);
    }
    
    map<string,set<int> >::iterator m_it=data.begin();
    while(m_it!=data.end()){
        cout<<(*m_it).first<<endl;
        set<int>::iterator s_it=(*m_it).second.begin();
        while(s_it!=(*m_it).second.end()){
            cout<<*s_it;
            s_it++;
            (s_it==(*m_it).second.end())?cout<<endl:cout<<" ";
        }
        m_it++;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.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;
	}
      }
    }
  }

  printf("%s\n%d", b[0].s, b[0].a);
  for(j=1;j<i;j++){
    if(strcmp(b[j].s, b[j-1].s) != 0){
      printf("\n");
      printf("%s\n%d", b[j].s, b[j].a);
    }
    else{
      printf(" %d", b[j].a);
    }
  }
  printf("\n");

  return 0;
}

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

int main(){
  pair< string ,int > book[1001];
  string name;
  int n=0 ,num;
  bool flag=true;
  while( cin >> name >> num ){
    book[n].first  = name;
    book[n].second = num;
    n++;
  }
  
  sort( book ,book+n );
  for( int i=0 ; i<n ; i++ ){
    for( int j=0 ; j<n ; j++ ){
      if( i != j && book[i].first.find(book[j].first) != string::npos ){
	book[j].first = ' ';
      }
    }
  }
  for( int i=0 ; i<n ; i++ ){
    if( book[i].first.compare( " " ) == 0 )
      cout << ' ' << book[i].second;
    else{
      if( !i ){
	cout << book[i].first << endl << book[i].second;
      }
      else{
	cout << endl << book[i].first << endl << book[i].second;
      }
    }
  }
  cout << endl;
}