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 <cstdio>
#include <cstdint>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

int main() {
  std::map<std::string, std::vector<int>> index;
  while (true) {
    char buf[32];
    int p;
    if (scanf("%s %d", buf, &p) == EOF) break;
    index[buf].push_back(p);
  }

  for (auto &p: index) {
    printf("%s\n", p.first.c_str());
    auto v=p.second;
    std::sort(v.begin(), v.end());
    for (size_t i=0; i<v.size(); ++i)
      printf("%d%c", v[i], i+1<v.size()? ' ':'\n');
  }
}

C++: #include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
int main()
{
  multimap< string, int > m;
  string str;
  int n;
  while(cin >> str >> n){
    m.insert( map<string,int>::value_type(str,n) );
  }
  map<string,int>::iterator it = m.begin();
  while(it != m.end()){
    cout << (*it).first << endl;
    n = m.count((*it).first);
    set<int> s;
    while(n--){
      s.insert((*it).second);
      it++;
    }
    set<int>::iterator i = s.begin();
    cout << *i;
    i++;
    while(i != s.end()){
      cout << " " << *i;
      i++;
    }
    cout << endl;
  }
  return 0;
}

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

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

int page;
char buf[100000];
map<string, vector<int> > table;

int main() {
  while (1) {
    if (scanf(" %s%d", buf, &page) != 2) break;
    table[buf].push_back(page);
  }

  for (auto itr=table.begin(); itr!=table.end(); itr++) {
    sort(itr->second.begin(), itr->second.end());
    itr->second.erase(unique(itr->second.begin(), itr->second.end()), itr->second.end());

    printf("%s\n", itr->first.c_str());
    printf("%d", itr->second[0]);
    for (int i=1; i<itr->second.size(); i++) {
      printf(" %d", itr->second[i]);
    }
    puts("");
  }
}

C++: #include<map>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  map<string,vector<int> > index;
  string m;
  int d;
  while(cin>>m>>d){
    index[m].push_back(d);
  }
  map<string,vector<int> >::iterator it;
  for(it = index.begin() ; it!=index.end() ; it++){
    sort( (*it).second.begin() , (*it).second.end() );
    cout<<(*it).first<<endl;
    for(int i = 0 ; i < (*it).second.size() ; i++){
      cout<<(*it).second[i]<<(i == (*it).second.size()-1?'\n':' ');
    }
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string name[111], a;
	int na, kazu[111], date[111][111], b;
	for (int i = 1; i <= 101; i++) {
		kazu[i] = 0;
	}
	na = 0;
	while (cin >> a >> b) {
		for (int i = 1; i <= na; i++) {
			if (name[i] == a) {
				kazu[i] = kazu[i] + 1;
				date[i][kazu[i]] = b;
				goto a;
			}
		}
		na = na + 1;
		name[na] = a;
		kazu[na] = 1;
		date[na][kazu[na]] = b;
	a:;
	}
	string aa;
	int bb,min,mi;
	for (int i = 1; i <= na; i++) {
		aa = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz";
		for (int z = 1; z <= na; z++) {
			if (aa >= name[z]) {
				aa = name[z];
				bb = z;
			}
		}
		cout << aa << endl;
		name[bb] = "zzzzzzzzzzzzzzzzzzzzzzzz";
		for (int z = 1; z <= kazu[bb]; z++) {
			min = 9999;
			for (int m = 1; m <= kazu[bb]; m++) {
				if (date[bb][m] <= min) {
					min = date[bb][m];
					mi = m;
				}
			}
			cout << min << " ";
			date[bb][mi] = 9999;
		}
		cout << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	char w[1024];
	char p[1024];
	char word[128][1024];
	char page[128][1024];
	char tmp[1024];
	int i;
	int j;
	int n;
	
	i = 0;
	while (scanf("%s %s", w, p ) != EOF){
		word[i][0] = '\0';
		i++;
		for (j = 0; j <= i; j++){
			if (strcmp(word[j], w) == 0){
				strcat(page[j], " ");
				strcat(page[j], p);
				i--;
			}
			if (word[j][0] == '\0'){
				strcpy(word[j], w);
				strcpy(page[j], p);
			}
		}
	}
	n = i;
	for (i = 0; i < n; i++){
		for (j = n; j > i; j--){
			if (strcmp(word[j], word[j - 1]) < 0){
				strcpy(tmp, word[j]);
				strcpy(word[j], word[j - 1]);
				strcpy(word[j - 1], tmp);
				strcpy(tmp, page[j]);
				strcpy(page[j], page[j - 1]);
				strcpy(page[j - 1], tmp);
			}
		}
	}
	
	for (i = 0; i <= n; i++){
		printf("%s\n%s\n", word[i], page[i]);
	}
	
	return (0);
}

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

using namespace std;

struct WordCount{
  string word;
  vector<int> page;
};

void PushWordCount(const string, const int, vector<WordCount>&);
bool Compare(const WordCount&, const WordCount&);

int main(){
  int Page;
  string Word;
  vector<WordCount> words;

  while(cin >> Word >> Page)
    PushWordCount(Word, Page, words);

  sort(words.begin(), words.end(), Compare);

  for(vector<WordCount>::size_type i=0; i != words.size(); ++i){
    cout << words[i].word << endl;
    sort(words[i].page.begin(), words[i].page.end());

    for(vector<int>::size_type j=0; j < words[i].page.size()-1; ++j)
      cout << words[i].page[j] << " ";
    cout << words[i].page[words[i].page.size()-1] << endl;
  }

  return 0;
}

void PushWordCount(const string Word, const int Page, vector<WordCount>& words){
  int isFound = 0;
  WordCount NewWord;
  vector<WordCount>::iterator iter = words.begin();

  while(iter != words.end()){
    if(iter->word == Word){
      isFound = 1;
      iter->page.push_back(Page);
      break;
    }
    ++iter;
  }
  
  if(isFound == 0){
    NewWord.word = Word;
    NewWord.page.push_back(Page);
    words.push_back(NewWord);
  }
}

bool Compare(const WordCount& x, const WordCount& y){
  return (x.word < y.word);
}

C++: #include<bits/stdc++.h>
using namespace std ;
#define Psi pair<string,int>

main(){
	int n ;
	string s ;
	vector<Psi> V ;
	
	while( cin >> s ){
		if( cin.eof() ) break ;
		cin >> n ;
		
		V.push_back( Psi(s,n) ) ;
	}
	
	sort( V.begin() , V.end() ) ;
	
	string t = "0a" ;
	for( int i=0 ; i<V.size() ; i++ ){
		if( V[i].first != t ){
			if( i ) cout << endl ;
			cout << V[i].first << endl ;
			cout << V[i].second ;
		}
		else cout << " " << V[i].second ;
		
		t = V[i].first ;
	}
	
	cout << endl ;
}