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

using namespace std;

int main(){
	map< string , vector<int> > list;
	set<string> namelist;
	char cself[256];
	int iself;
	while(scanf("%s %d",cself,&iself) != EOF){
		list[cself].push_back(iself);
		namelist.insert(cself);
	}
	vector<int>::iterator it;
	set<string>::iterator nit;
	
	//sort(namelist.begin(),namelist.end());
	
	bool f;
	
	for(nit = namelist.begin();nit != namelist.end();nit++){
		printf("%s\n",(*nit).c_str());
		f = false;
		sort(list[*nit].begin(),list[*nit].end());
		for(it = list[*nit].begin();it < list[*nit].end();it++){
			if(f){
				printf(" ");
			}
			printf("%d",*it);			
			f = true;
		}
		printf("\n");
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    string buf_s,min="\0";
    int buf_i,min_a,old_a;
    bool f,f1;
    vector <string> s;
    vector <int> a;
    vector <bool> pr;
    while(cin>>buf_s>>buf_i){
    //    cout<<buf_s<<buf_i<<endl;
        s.push_back(buf_s);
        a.push_back(buf_i);
        pr.push_back(0);
    }
    for(int lop=0; lop<s.size();){
        f=1;
        for(int i=0; i<s.size(); i++){
            if((min>s[i]||f)&&!pr[i]){
                min=s[i];
                f=0;
            }
        }
        cout<<min<<endl;
        f=1;
        while (1) {
            f1=1;
            min_a=0;
            for(int i=0; i<s.size(); i++){
                if(s[i]==min){
                    if((a[min_a]>a[i]||f1)&&(pr[i]==0)){
                        min_a=i;
                        f1=0;
                    }
                }
            }
            if(f1)
                break;
            else{
                if(f){
                    cout<<a[min_a];
                    f=0;
                }
                else
                    cout<<" "<<a[min_a];
                pr[min_a]=1;
                lop++;
            }
        }
        cout<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main(void)
{
	map<string, vector<int> > index;
	vector<string> name;
	string key;
	int page;
	while((cin>>key>>page))
	{
		int flg=0;
		for(int f1=0;f1<name.size();f1++)
		{
			if(name[f1]==key)flg=1;
		}
		if(!flg)name.push_back(key);
		index[key].push_back(page);
	}
	sort(name.begin(),name.end());
	for(int f1=0;f1<name.size();f1++)
	{
		sort(index[name[f1]].begin(),index[name[f1]].end());
		cout<<name[f1]<<endl;
		for(int f2=0;f2<index[name[f1]].size();f2++)
		{
			cout<<index[name[f1]][f2]<<" ";
		}
		printf("\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] << ':';
		for (int m = 0; m < pages[i].size(); m++) {
			cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}

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

using namespace std;

int main()
{
  vector<pair<string,int>> com;
  string s;
  int a,count;
  string m;

  count = 0;

  while(cin>>s>>a){
    com.push_back(make_pair(s,a));
    ++count;
  }

  sort(com.begin(),com.end());

  for(int i = 0;i<count;++i){
    pair<string,int> p = com[i];
    if(i == 0){
      cout<<p.first<<endl;
      cout<<p.second;
      m = p.first;
    }
    else{
      if(m == p.first){
        cout<<" "<<p.second;
      } 
      else{
        cout<<endl;
        cout<<p.first<<endl;
        cout<<p.second;
        m = p.first;
      }
    }
  }

  cout<<endl;

  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
	string s;
	int n;
	map<string,vi> mp;
	vector<string> sent;

	while(cin>>s>>n){
		if(mp[s].size()==0)sent.pb(s);
		mp[s].pb(n);
	}

	sort(all(sent));
	rep(i,sent.size()){
		cout<<sent[i]<<endl;
		vi a;
		rep(j,mp[sent[i]].size()){
			a.pb(mp[sent[i]][j]);
		}
		sort(all(a));
		rep(i,a.size()){
			if(i!=0)cout<<" ";
			cout<<a[i];
		}
		cout<<endl;
	}

}

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

int main(){
	string phrase;
	string page;
	string space = " ";
	vector<string> str;
	vector<string>::iterator p;
	p = str.begin();
	
	cin >> phrase >> page;
	phrase.append(space);
	phrase.append(page);
	str.push_back(phrase);
	
	while(cin >> phrase >> page){
	  //	cin >> phrase;
	  //	if(phrase == "end") break;
	  //	cin >> page;
		

		for(p = str.begin(); p != str.end(); p++){
			string a = *p;
			int b = a.find_first_of(" ", 0);
			string c = a.substr(0, b);
			if(phrase == c){
				phrase = *p;
				phrase += space;
				phrase += page;
				*p = phrase;
				break;
			}
		}
		if(p == str.end()){
			phrase.append(space);
			phrase.append(page);
			str.push_back(phrase);
		}
		
	}
	
	sort(str.begin(), str.end());
	for(p = str.begin(); p != str.end(); p++){
		cout << *p << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

struct BK{string st;int p;};
int main(){
string str;
int N,iii=0;
BK B[101],T;
while(cin>>str>>N){
B[iii].st=str;B[iii].p=N;
iii++;
}
for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st<B[j-1].st){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st==B[j-1].st&&B[j].p<B[j-1].p){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
{if(i==0)cout<<B[0].st<<endl<<B[0].p;
else if(i>0&&B[i].st==B[i-1].st){cout<<" "<<B[i].p;}
else cout<<endl<<B[i].st<<endl<<B[i].p;
}
cout<<endl;
return 0;
}