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>
#define MAX_N 101
using namespace std;

typedef struct{
string name;
int page;
}index;
index a[MAX_N];
index temp;
int n;
int main(){
	n=0;
	while(cin >> a[n].name >> a[n].page){
		n++;
	}

	for(int i=0;i<n-1;i++){
		for(int j=0;j<n-1-i;j++){
			if(a[j].name>a[j+1].name){
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}else if(a[j].name==a[j+1].name&&a[j].page>a[j+1].page){
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}
	cout << a[0].name << endl;
	cout << a[0].page;
	for(int i=1;i<n;i++){
		if(a[i-1].name!=a[i].name){
			cout <<endl << a[i].name << endl;
			cout <<a[i].page;
		}else if(a[i-1].name==a[i].name){
			cout << " "<<a[i].page;
		}
	}
	return 0;
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
typedef pair<string,int> P;
int n;
int main(){
	string str;
	map<string,std::vector<int> > data;
	while(cin>>str>>n){
		data[str].push_back(n);
	}
	map<string,vector<int> >::iterator it =data.begin();
	for(;it!=data.end();it++){
		cout <<(*it).first<<endl;
		vector<int>v =(*it).second;
		sort(v.begin(),v.end());
		for(int i = 0;i <v.size();i++){
			if(i)cout <<" ";
			cout <<v[i];
		}
		cout <<endl;
	}
	return 0;
}

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

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

C++: #include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

vector<pair<string, int>> v;
vector<pair<string, vector<int>>> l;
vector<string> w;

bool fa(int index) {
	for (int i = 0; i < l.size(); i++) {
		if (l[i].first == v[index].first) {
			l[i].second.push_back(v[index].second);
			return true;
		}
	}
	l.push_back({ v[index].first,vector<int>(1,v[index].second) });
	w.push_back(v[index].first);
	return false;
}

int search(int index) {
	for (int i = 0; i < l.size(); i++) {
		if (w[index] == l[i].first)
			return i;
	}
	return -1;
}

int main(){
	string s;
	int p;
	while (cin >> s >> p && p != 0) {
		v.push_back(pair<string, int>({ s,p }));
	}
	for (int i = 0; i < v.size(); i++) {
		fa(i);
	}
	sort(w.begin(), w.end());
	for (int i = 0; i < l.size(); i++) {
		sort(l[i].second.begin(), l[i].second.end());
	}
	for (int i = 0; i < w.size(); i++) {
		int index = search(i);
		cout << w[i] << endl;
		cout << l[index].second[0];
		for (int j = 1; j < l[index].second.size(); j++) {
			cout << " " << l[index].second[j];
		}
		cout << endl;
	}

	return 0;
}

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

typedef pair<string, int> P;

P words[110];

int main() {
  int i=0;

  string name; int page;
  while(cin >> name >> page) {
    words[i].first = name;
    words[i].second = page;

    i++;
    // cout << name << page << endl;
  }

  int n = i;

  
  for (int j=0; j<n-1; j++) {
    for (int k=0; k<n-1-j; k++) {
      if (words[k].first > words[k+1].first ||
	  (words[k].first == words[k+1].first &&
	   words[k].second > words[k+1].second)) {
	P temp = words[k];
	words[k] = words[k+1];
	words[k+1] = temp;
      }
    }
  }


  for (int j=0; j<n; j++) {
    cout << words[j].first << " " << words[j].second << endl;
  }
  
  /*
  bool cont = false;
  for (int j=0; j<n; j++) {
    if (words[j].first == words[j+1].first) {
      if (!cont) {
	cout << words[j].first << endl;
	cont = true;
      }
    }
  }
  */
  
  
}

C++: #include <bits/stdc++.h>
using namespace std;pair<string,int> a[1];int main(){int t=0,g,i;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(i=1;i<t;i++){bool n=0;f=a[i].first,g=a[i].second;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<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  map<string, vector<int> > word;
  string s;
  int n;
  while(cin >>s>>n){
    word[s].push_back(n);
  }
  for(map<string, vector<int> >::iterator i=word.begin(); i!=word.end(); i++){
    sort(i->second.begin(),i->second.end());
    cout <<i->first<<endl<<i->second[0];
    for(int j=1; j<i->second.size(); j++){
      cout <<" "<<i->second[j];
    }
    cout <<endl;
  }
  return 0;
}

C++: #include<map>
#include<set>
#include<string>
#include<iostream>

using namespace std;

int main()
{
	string key;
	int page;
	map< string, set<int> > dic;

	while (cin >> key >> page)
	{
		dic[key].insert(page);
	}

	for (map< string, set<int> >::iterator it_dic = dic.begin(); it_dic != dic.end(); ++it_dic)
	{
		cout << it_dic->first << endl;
		for (set<int>::iterator it = it_dic->second.begin(); it != it_dic->second.end(); ++it)
		{
			if (it != it_dic->second.begin())
			{
				cout << " ";
			}
			cout << *it;
		}
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <functional>

using namespace std;

void solve()
{
	map<string, priority_queue<int, vector<int>, greater<int> > > Map;
	string str;
	int page;
	while(cin >> str >> page)
	{
		Map[str].push(page);
	}
	for(map<string, priority_queue<int, vector<int>, greater<int> > >::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
	{
		cout << Ite->first << endl;
		bool FirstFlag = true;
		while(!Ite->second.empty())
		{
			if(FirstFlag)
			{
				cout << Ite->second.top();
				FirstFlag = false;
			}
			else
			{
				cout << " " << Ite->second.top();
			}
			Ite->second.pop();
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}