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

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

C++: #include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;main(int n){string s;map<string,set<int> >z;map<string,set<int> >::iterator q;set<int>::iterator x;while(cin>>s>>n)z[s].insert(n);for(q=z.begin();q!=z.end();cout<<endl){cout<<(s=q++->first)<<endl;for(x=z[s].begin(),n=0;x!=z[s].end();cout<<*x++)if(n++)cout<<" ";}return 0;}

C++: #pragma warning(disable:4996)
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;

int main(){
	string word;
	int page;
	map<string, set<int>> indexs;
	while (cin >> word >> page){
		indexs[word].insert(page);
	}
	for (auto index : indexs){
		cout << index.first << endl;
		for (auto page_a : index.second){
			cout << page_a<<" ";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;

string s[3]={"HIT","HOMERUN","OUT"};


int main(){
	map<string,vi> m;
	string s;
	int a;
	while(cin>>s>>a){
		m[s].pb(a);
	}
	for(map<string,vi>::iterator it=m.begin(); it!=m.end(); it++){
		bool f=false;
		cout<<it->fi<<endl;
		sort(all(it->se));
		for(int i=0; i<it->se.size(); i++){
			if(f)cout<<" ";
			cout<<it->se[i];
			f=true;
		}
		cout<<endl;
	}
}

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;
	while(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);
	}
	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;
		vector<int>::iterator ite = d[k].begin();
		for(ite=d[k].begin();ite!=d[k].end();++ite) {
			if (ite == d[k].begin())
				cout << *ite;
			else
				cout << " " << *ite;
		}
		cout << "\n";
		t++;
	}
}

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

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));
    }
    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] = s;
	vector<int> ws = nn[i];
	nn[i] = nn[j];
	nn[j] = ws;
      }
    }
  }
  for(int i = 0 ; i < ss.size() ; i ++){
    cout<<ss[i]<<endl;
    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 <string>
#include <algorithm>

using namespace std;

struct P {
	string a;
	int b;
};

int main() {
	string a;
	int b;
	P retu[110];
	int i = 0;
	while (cin >> a >> b) {
		P p;
		p.a = a;
		p.b = b;
		retu[i] = p;
		i++;
	}
	for (int j = i; j > 0; j--) {
		for (int k = 0; k < j-1; k++) {
			if (retu[k].a > retu[k+1].a) {
				swap(retu[k], retu[k+1]);
			} else if (retu[k].a == retu[k+1].a) {
				if (retu[k].b > retu[k+1].b) {
					swap(retu[k], retu[k+1]);
				}
			}
		}
	}
	for (int j = 0; j < i; j++) {
		if (j == 0) {
			cout << retu[0].a << endl << retu[0].b;
		} else {
			if (retu[j].a == retu[j-1].a) {
				cout << ' ' << retu[j].b;
			} else {
				cout << endl << retu[j].a << endl << retu[j].b;
			}
		}
	}
	cout << endl;
	return 0;
}

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

int main() {
	vector<string> words;
	vector<vector<int>> pages;
	string word; int page;
	while(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++) {
			cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}