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 <iostream>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  map< string, vector<int> > dict;
  while( 1 ) {
    string word;
    int page;
    if( !( cin >> word ) ){ break; }
    cin >> page;
    if( dict.find( word ) == dict.end() ) {
      pair< string, vector<int> > p;
      p.first = word;
      p.second.push_back( page );
      dict.insert( p );
    } else {
      dict[ word ].push_back( page );
    }
  }

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

  return EXIT_SUCCESS;
}

C++: #include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
using pair_t = pair< string,vector<int> >;

int main() {
	string word;
	int page;
	vector<pair_t> v;
	while (cin >> word >> page) {
		auto word_pos = find_if(v.begin(),v.end(),[word](pair_t p){return p.first == word;});
		if (word_pos == v.end()) { // if word not exist
			v.push_back({word,{page}});
		} else {
			word_pos->second.push_back(page);
		}
	}
	sort(v.begin(),v.end(),[](pair_t p_1,pair_t p_2){return p_1.first < p_2.first;});
	for (auto i = v.begin();i != v.end();++i) {
		sort(i->second.begin(),i->second.end());
		cout << i->first << endl;
		for_each(i->second.begin(),i->second.end(),[i](int n){cout << n << (n == i->second.back() ? "\n" : " ");});
	}
}

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

int main(){
  map< string , vector<int> > mp;
  
  string str;
  int num;
  
  while( cin>>str>>num ){
    mp[ str ].push_back( num );
  }

  //for( pair<string,vector<int> > p : mp)
  for( auto  p : mp){
    string name=p.first;
    vector<int> v=p.second;
    sort(v.begin(),v.end());
    
    cout<<name<<endl;

    for(int i=0;i<(int)v.size();i++){
      if(i>0)cout<<' ';
      cout<<v[i];
    }
    cout<<endl;
  }
  
  return 0;
}

C++: #include<iostream>
#pragma warning(disable:4786)
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	for(int l=0;l<8;l++){
		getline(cin, a);
		string b, h = "";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a.length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
		d[b].clear();
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k << endl;
		for (int i = 0; i != d[k].size(); i++) {
			cout << " " << d[k][i];
		}
		cout << endl;
		t++;
	}
}

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

int main()
{
	map<string, vector<int>>s;
	string a; int b;
	cin >> a >> b;
	if (cin.fail()) {}
	else {
		vector<int>r(0);
		s.insert(pair<string, vector<int>>(a, r));
		s[a].push_back(b);
		while (1) {
			cin >> a >> b;
			if (cin.fail())break;
			for (auto c = s.begin(); c != s.end(); c++) {
				if (a == c->first) { c->second.push_back(b); break; }
				auto d = c;
				d++;
				if (d == s.end()) { vector<int>r(0); s.insert(pair<string, vector<int>>(a, r));  s[a].push_back(b); break; }
			}
		}
		for (auto e = s.begin(); e != s.end(); e++) {
			sort(e->second.begin(), e->second.end());
			cout << e->first << endl;
			for (int f : e->second) {
				cout << f << " ";
			}
			cout << "\b" << endl;
		}
	}
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct Book{
    string s;
    vector<int> page;
};

int main(){
    string s;
    int p, i = 0;
    struct Book book[105];
    while(cin >> s >> p){
        bool c = true;
        rep(j,i){
            if(book[j].s == s){
                book[j].page.push_back(p);
                c = false;
            }
        }
        if(c){
            book[i].s = s;
            book[i].page.push_back(p);
            i++;
        }
    }
    rep(j,i){
        rep(k,i){
            if(book[k].s < book[k + 1].s){
                struct Book g = book[k];
                book[k] = book[k + 1];
                book[k + 1] = g;
            }
        }
    }
    rep(j,i){
        debug(book[j].s)
        sort(book[j].page.begin(), book[j].page.end());
    }
    for(int j = i; j >= 0; j--){
        cout << book[j].s << endl;
        rep(k, book[j].page.size()){
            if(k) cout << ' ';
            cout << book[j].page[k];
        }
        cout << endl;
    }
}

C++: #include <bits/stdc++.h>
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;
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 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())

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

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main() {
  string s;
  int p;  
  map<string, VI> index;

  while(cin >> s >> p) index[s].PB(p);

  map<string, VI>::iterator it = index.begin();
  while(it != index.end()) {
    cout << it->first << endl;
    sort(ALL(it->second));
    REP(i, it->second.size()) {
      cout << it->second[i];
      if(i != it->second.size()-1) cout << ' ';
    }
    cout << endl;
    it++;
  } 
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    pair<string, int> t[1010];
    int i;
    for(i=0; cin >> t[i].first >> t[i].second; i++);
    sort(t, t+i);
    cout << t[0].first << "\n";
    cout << t[0].second;
    for(int j=1; j<i; j++){
        if(t[j-1].first==t[j].first){
            cout << " " << t[j].second;
        }
        else{
            cout << "\n";
            cout << t[j].first << "\n";
            cout << t[j].second;
        }
    }
    cout << "\n";
}