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

int main() {
	vector<string> words;
	vector<vector<int> > pages;
	string word; int page;
	for(int k=0;k<8;k++) {
    cin>>word>>page;
		bool is_there = false; int word_place;
		for (int i = 0; i < words.size(); i++) {
			if (word == words[i]) {
				is_there = true;
				word_place = i;
			}
		}
		if (is_there) {
			pages[word_place].push_back(page);
		}
		else {
			words.push_back(word);
			vector<int>* x = new vector<int>;
			pages.push_back(*x);
			pages[pages.size() - 1].push_back(page);
		}
	}
	for (int i = 0; i < words.size() - 1; i++) {
		for (int j = 0; j < words.size() - 1; j++) {
			if (words[j] > words[j + 1]) {
				string tmp_w=words[j];
				words[j] = words[j + 1];
				words[j + 1] = tmp_w;
				vector<int> tmp_p=pages[j];
				pages[j] = pages[j + 1];
				pages[j + 1] = tmp_p;
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		for (int j = 0; j < pages[i].size()-1; j++) {
			for (int c = 0; c < pages[i].size()-1; c++) {
				if (pages[i][c] > pages[i][c + 1]) {
					int tmp=pages[i][c];
					pages[i][c] = pages[i][c + 1];
					pages[i][c + 1] = tmp;
					}
			}
		}
	}
	for (int i = 0; i < words.size(); i++) {
		cout << words[i] << endl;
		for (int m = 0; m < pages[i].size(); m++) {
      if(pages[i].size()-1==m)cout<<pages[i][m];
			else cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	map<string, vi> table;
	char str[32];
	int page;
	while(scanf("%s%d", str, &page) != EOF){
		string s(str);
		if(table.count(s))
			table[s].push_back(page);
		else
			table[s] = vi(1, page);
	}

	for(map<string, vi>::iterator itr = table.begin(); itr != table.end(); ++itr){
		sort(itr->second.begin(), itr->second.end());
		puts(itr->first.c_str());
		rep(i, itr->second.size())
			printf("%s%d", i?" ":"", itr->second[i]);
		puts("");
	}

	return 0;
}

C++: #include <iostream>
#include<string>
#include<utility>
using namespace std;
int main() {
    pair<string,int> go[100000];
    int i=0;
    while(cin>>go[i].first>>go[i].second){
        i++;
    }
    int at;
    string fir;
    at=0;
    for(int l=0;l<i;++l){
        fir="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
        for(int j=l;j<i;++j){
            if(go[j].first<=fir){
                fir=go[j].first;
                at=j;
            }
        }
        swap(go[at],go[l]);
    }
    fir=go[0].first;
    for(int k=1;k<i;++k){
        if(go[k].first!=fir){
        fir=go[k].first;
        }
        else{
            go[k].first="-1";
        }
    }
    int min=100000;
    
    for(int k=0;k<i;++k){
        at=k;
        min=100000;
        for(int l=k;l<i;++l){
            if(l!=k&&go[l].first!="-1"){
                break;
            }
            if(go[l].second<min){
                min=go[l].second;
                at=l;
            }
        }
        swap(go[k].second,go[at].second);
    }
    for(int k=0;k<i;++k){
        if(go[k].first=="-1"){
            cout<<" "<<go[k].second;
        }
        else if(go[k].first!="-1"&&k!=0){
            cout<<endl<<go[k].first<<endl<<go[k].second;
        }
        else{
            cout<<go[k].first<<endl<<go[k].second;

        }
    }
    cout<<endl;
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
class data{
public:
  string words;  
  int page;
  bool operator < (const data&s)const{
    if(words < s.words) return true;
    else if(words > s.words) return false;
    else{
      if(page < s.page) return true;
      else return false;
    }
  }
};
int main(){
  int i=0;
  data in[1000];
  while(1){
    in[i].words="";
    char c;
    if(scanf("%c", &c)==EOF) break;
    in[i].words+=c;
    for(int j=1;;j++){
      scanf("%c", &c);
      if(c==' ') break;
      in[i].words+=c;
    }
    cin >> in[i].page;
    getchar();
    i++;
  }
  
  sort(in,in+i);

  cout << in[0].words << endl << in[0].page;
  for(int j=1;j<i;j++){
    if(in[j-1].words != in[j].words){
      cout << endl;
      cout << in[j].words << endl << in[j].page;
    }
    else{
      cout << ' ' << in[j].page;
    }
  }
  cout << endl;
  return 0;
}

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

int main(){
  int i,size;
  vector<string> word;
  vector<int> page;
  string tmpw;
  int tmpp;
  set<string> idw;
  set<int> idp;

  while(cin >> tmpw >> tmpp){
    word.push_back(tmpw);
    page.push_back(tmpp);
  }

  size = word.size();
  for(i=0;i<size;i++)idw.insert(word[i]);

  size = page.size();
  set<string>::iterator itw = idw.begin();
  while(itw!= idw.end()){
    cout << *itw<< endl;
    for(i=0;i<size;i++){
      if(*itw== word[i]){
	idp.insert(page[i]);
      }
    }
    set<int>::iterator itp = idp.begin();
    int flag = 0;
    while(itp != idp.end()){
      if(flag)cout << " " << *itp;
      else cout << *itp;
      flag = 1;
      itp++;
    }
    cout << endl;
    idp.clear();
    itw++;
  }

  return 0;
}

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

int main(){
	string s;
	int n;
	map<string, vector<int> > m;
	while (1){
		if (cin.eof()) break;
		cin >> s >> n;
		m[s].push_back(n);
	}
	map<string, vector<int> >::iterator it = m.begin();
	while (it != m.end()){
		int flag = 0;
		cout << (*it).first << endl;
		sort((*it).second.begin(), (*it).second.end());
		for (int i = 0; i < (*it).second.size(); i++){
			if (!flag){
				cout << (*it).second[i];
				flag = 1;
			}
			else cout << " " << (*it).second[i];
		}
		cout << endl;
		++it;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st;
	map<string, vector<int>>mp;
	while (getline(cin,st)) {
		string name = st.substr(0, st.find(' '));
		int page = stoi(st.substr(st.find(' ') + 1));
		mp[name].push_back(page);
	}
	for (auto m : mp) {
		cout << m.first << endl;
		for (int i = 0; i < m.second.size(); ++i) {
			cout << m.second[i];
			if (i == m.second.size() - 1)cout << endl;
			else cout << " ";

		}
	}
	return 0;
}