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<vector>
#include<string>
#include<algorithm>
using namespace std;

char returnc(char c){
  if('a'<=c && c<='z'){
    if(c=='z')return 'a';
    return ++c;
  }
  return c;
}
int main(void){
  string s;
  int n;
  vector<string> ss;
  vector<vector<int> > nn;
  while(cin>>s>>n){
    if(ss.empty()){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      continue;
    }
    bool ok = true;
    for(int i = 0 ; i < ss.size() ; i ++){
      if(ss[i] == s){
	nn[i].push_back(n);
	ok = false;
      }
    }
    if(ok){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      
    }
  }
  
  for(int i = ss.size() - 1 ; i >= 0 ; i --){
    for(int j = 0 ; j < i ; j ++){
      if(ss[i] < ss[j]){
	string w = ss[i];
	ss[i] = ss[j];
	ss[j] = w;
	vector<int> ws = nn[i];
	nn[i] = nn[j];
	nn[j] = ws;
      }
    }
  }
  for(int i = 0 ; i < ss.size() ; i ++){
    cout<<ss[i]<<endl;
    sort(nn[i].begin(),nn[i].end());
    for(int j = 0 ; j < nn[i].size()-1 ; j ++){
      cout<<nn[i][j]<<" ";
    }
    cout<<nn[i][nn[i].size() - 1 ]<<endl;
  }
}

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

using namespace std;

int main()
{
	map< string, vector<int> > m;
	string word;
	int page;

	while (cin >> word >> page){
		if (m.count(word)) m[word].push_back(page);
		else {
			vector<int> v;

			v.push_back(page);
			m.insert(make_pair(word, v));
		}
	}

	for (map< string, std::vector<int> >::iterator it = m.begin(); it != m.end(); it++){
		cout << it->first << endl;
		sort(it->second.begin(), it->second.end());
		for (int i = 0; i < it->second.size(); i++){
			printf("%d%c", it->second[i], i == it->second.size() - 1 ? '\n' : ' ');
		}
	}
}

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

using namespace std;
typedef pair<string, int> psi;

int main(){
	vector<psi> words;
	while(!cin.eof()){
		psi entry;
		cin >> entry.first >> entry.second;
		words.push_back(entry);
	}
	sort(words.begin(), words.end());
	string word = "";
	for(int i = 1; i < words.size(); ++i){
		if(words[i].first != word){
			word = words[i].first;
			cout << word << endl;
		}
		cout << words[i].second;
		if(i == words.size() - 1 || words[i + 1].first != word){
			cout << endl;
		}else{
			cout << " ";
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
map<string,priority_queue<int,vector<int>,greater<int> > > Map;
signed main(void){
	ios::sync_with_stdio(false);
	string s;
	int page;
	while(cin>>s>>page)
		Map[s].push(page);
	for(map<string,priority_queue<int,vector<int>,greater<int> > >::iterator it=Map.begin();it!=Map.end();++it){
		cout<<it->first<<endl;
		while(!it->second.empty()){
			cout<<it->second.top()<<" ";
			it->second.pop();
		}
		cout<<endl;
	}
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  string str;
  map<string,vector<int> > dic;
  while((cin >> str)){
    int p;cin >> p;
    dic[str].push_back(p);
  }
  map<string,vector<int> >::iterator it = dic.begin();
  while( it != dic.end() ){
    cout << (*it).first << endl;
    sort((*it).second.begin(),(*it).second.end());
    cout << (*it).second[0];
    for(int i = 1;i < (*it).second.size();i++){
      cout << " " <<(*it).second[i];
    }
    cout << endl;
    ++it;
  }
  return 0;
}

C++: //============================================================================
// Name        : aoj0105.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

typedef struct{
	char word[31];
	int page;
}Quate;

int compare(const void *a,const void *b){
	Quate qa, qb;
	qa = *(Quate *)a;
	qb = *(Quate *)b;
	if(strcmp(qa.word,qb.word) != 0){
		return strcmp(qa.word,qb.word);
	}else{
		return qa.page - qb.page;
	}
}


int main() {
	char tmp[31] = "";
	Quate q[1000];
	int n = 0, i;
	while(scanf("%s%d%*c",q[n].word,&q[n].page) != EOF){
		n++;
	}
	qsort(q,n,sizeof(q[0]),compare);
	for(i = 0;i < n;i++){
		if(strcmp(tmp,q[i].word) == 0){
			printf(" %d",q[i].page);
		}else{
			if(strcmp(tmp,"") != 0){
				printf("\n");
			}
			printf("%s\n%d",q[i].word,q[i].page);
		}
		strcpy(tmp,q[i].word);
	}
	printf("\n");

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<string, int> P;

int main() {
  string word;
  int page;
  vector<P> list;
  while (cin >> word >> page) {
    list.push_back(P(word, page));
  }
  sort(list.begin(), list.end());
  word = "";
  for (vector<P>::iterator it=list.begin(); it!=list.end(); it++) {
    if (word != it->first) {
      if (!word.empty()) cout << endl;
      word = it->first;
      cout << word << endl;
      cout << it->second;
    } else {
      cout << " " << it->second;
    }
  }
  cout << endl;
  return 0;
}