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<algorithm>
using namespace std;
string tn[100];
int tp[100][100],tt[100];
int main(){
	string a;
	int b,top=0;
	while(cin>>a>>b){
		bool t=true;
		for(int i=0;i<top;i++){
			if(tn[i]==a){
				t=false;
				tp[i][tt[i]]=b;
				tt[i]++;
			}
		}
		if(t==true){
			tn[top]=a;
			tp[top][0]=b;
			tt[top]=1;
			top++;
		}
	}
	for(int i=0;i<top-1;i++){
			for(int j=top-1;j>i;j--){
				bool w=true;
				int k=0;
				while(true){
					if(tn[j][k]>tn[j-1][k])
						break;
					if(tn[j][k]<tn[j-1][k]){
						w=false;
						break;
					}
					k++;
					if(k==tn[j].size())
						break;
					if(k==tn[j-1].size()){
						w=false;
						break;
					}
				}
				if(w==false){
					string tmps=tn[j];
					tn[j]=tn[j-1];
					tn[j-1]=tmps;
					int tmph[100];
					for(int k=0;k<tt[j];k++)
						tmph[k]=tp[j][k];
					for(int k=0;k<tt[j-1];k++)
						tp[j][k]=tp[j-1][k];
					for(int k=0;k<tt[j];k++)
						tp[j-1][k]=tmph[k];
					int tmp=tt[j];
					tt[j]=tt[j-1];
					tt[j-1]=tmp;
				}
			}
		}
		for(int i=0;i<top;i++)
			sort(tp[i],tp[i]+tt[i]);
		for(int i=0;i<top;i++){
			cout<<tn[i]<<endl;
			cout<<tp[i][0];
			for(int j=1;j<tt[i];j++)
				cout<<" "<<tp[i][j];
			cout<<endl;
		}
	return 0;
}

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

using namespace std;
typedef pair<string, vector<int>> P;

void solve()
{
	vector<P> Vec;
	string str;
	while(cin >> str)
	{
		int n;
		cin >> n;
		bool existFlag = false;
		for(int i = 0; i < Vec.size(); ++i)
		{
			if(Vec[i].first == str)
			{
				Vec[i].second.push_back(n);
				existFlag = true;
				break;
			}
		}
		if(!existFlag)
		{
			vector<int> V;
			V.push_back(n);
			Vec.push_back(make_pair(str, V));
		}
	}
	sort(Vec.begin(), Vec.end());
	for(int i = 0; i < Vec.size(); ++i)
	{
		cout << Vec[i].first << endl;
		sort(Vec[i].second.begin(), Vec[i].second.end());
		for(int j = 0; j < Vec[i].second.size(); ++j)
		{
			cout << Vec[i].second[j] << " ";
		}
		cout << endl;
	}
}

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

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

using namespace std;

int main()
{
	map<string, vector<int> > index;
	vector<string> strv;
	string s;
	int p;
	
	while (cin >> s >> p){
		if (index.find(s) == index.end()){
			strv.push_back(s);
		}
		index[s].push_back(p);
	}
	sort(strv.begin(), strv.end());
	for (int i = 0; i < strv.size(); i++){
		sort(index[strv[i]].begin(), index[strv[i]].end());
		cout << strv[i] << endl;
		cout << index[strv[i]][0];
		for (int j = 1; j < index[strv[i]].size(); j++){
			cout << ' ' << index[strv[i]][j];
		}
		cout << endl;
	}
	
	return 0;
}

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

int main(){
    map <string, list<int> > book;
    string word;
    int page;
    while(cin >> word >> page){
        book[word].push_back(page);
    }
    map <string, list<int> >::iterator it = book.begin();
    while(it != book.end()){
        it->second.sort();
        it++;
    }
    it = book.begin();
    while(it != book.end()){
        cout << it->first << endl;
        list<int>::iterator list_it = it->second.begin();
        while(list_it != it->second.end()){
            if(list_it != it->second.begin()) cout << " ";
            cout << *list_it;
            list_it++;
        }
        cout << endl;
        it++;
    }
    return 0;
}

C++: ??£??£??£???

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

class Node{
public:
	string word;
	list <int> page;
	Node(string w,list<int> p){
		word=w;page=p;
	}
	bool operator < ( const Node &o ) const{
		return word > o.word;
	}
};
typedef list<Node> DB;
DB db;
list<Node>::iterator
getKey(string word){
	list<Node>::iterator it=db.begin();
	for(;it!=db.end();it++){
		if(it->word==word)return it;
	}
	return it;
}

list<Node>::iterator
getInsertPointWord(string word){
	list<Node>::iterator it=db.begin();
	for(;it!=db.end();it++){
		if(word < it->word)return it;
	}
	return it;
}
list<int>::iterator
getInsertPointNum(int num,list<Node>::iterator it){
	list<int>::iterator itp=it->page.begin();
	for(;itp!=it->page.end();itp++){
		if(num < *itp)return itp;
	}
	return itp;
}

void print(){
	list<Node>::iterator it=db.begin();
	for(;it!=db.end();it++){
		cout<<it->word<<endl;
		list<int>::iterator itp=it->page.begin();

		for(int i=0;itp!=it->page.end();itp++,i++){
			if(i)cout<<" ";
			cout<<*itp;
		}
		cout<<endl;
	}
}
int
main(){
	string word;
	int page;
	for(;cin>>word;){
		cin>>page;
		list<Node>::iterator it=getKey(word);
		if(it==db.end()){
			it=getInsertPointWord(word);
			list <int> pages;pages.push_back(page);
			db.insert(it,Node(word,pages));
		}
		else{
			list<int>::iterator itp=getInsertPointNum(page,it);
			it->page.insert(itp,page);
		}
	}
	print();
	return 0;
}

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

typedef struct{
	string word;	
	int page[100];
	int now;
}list;

int main(){
	list a[100];
	int b=0;
	
	string s;
	int n;
	
	while( cin >> s >> n ){
		
		bool find=false;
		for(int i=0; i<b; ++i){
			if(a[i].word==s){
				a[i].page[ a[i].now ]=n;
				a[i].now++;
				find=true;		
			}
		}	
		
		if( !find ){
			a[b].word=s;
			a[b].page[0]=n;
			a[b].now=1;
			b++;
		}	
		
	}
	
	for(int i=0; i<b; ++i) sort(a[i].page, a[i].page+a[i].now);	
		
	for(int i=0; i<b; ++i){
		for(int j=i; j<b; ++j){
			if(a[i].word > a[j].word) swap(a[i], a[j]);
		}	
	}	
	
	for(int i=0; i<b; ++i){
		cout << a[i].word << endl;	
		for(int j=0; j<a[i].now; ++j){
			if(j>0) printf(" ");
			printf("%d", a[i].page[j]);	
		}
		printf("\n");
	}
	
}

C++: #include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string s; int n;
	set<string>st;
	map<string, vector<int>>m;
	while (cin >> s >> n) {
		st.insert(s);
		m[s].push_back(n);
	}
	for (auto i = st.begin(); i != st.end(); i++) {
		string str = *i;
		cout << str << endl;
		sort(m[str].begin(), m[str].end());
		for (int j = 0; j < m[str].size(); j++) {
			if (j)cout << ' '; cout << m[str][j];
		}
		cout << endl;
	}
}