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

using namespace std;

int main(){
	string strInput;
	map< string,vector<int> > index;
	int intInput = 0;
	while(cin >> strInput >> intInput){
		index[strInput].push_back(intInput);
	}
	
	for(map< string,vector<int> >::iterator it = index.begin(); it != index.end() ; it++){
		sort( index[(*it).first].begin(),index[(*it).first].end() );
		cout << (*it).first << endl;
		for(int i = 0; i < index[(*it).first].size(); i++){
			cout <<  index[(*it).first][i];
			cout << ' ';
		}
		cout << endl;
	}

	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";
        }
    }
    for(int k=0;k<i;++k){
        if(go[k].first=="-1"){
            cout<<" "<<go[k].second;
        }
        else{
            cout<<endl<<go[k].first<<endl<<go[k].second;
        }
    }
    cout<<endl;
    return 0;
}

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

struct book_info{
	char phrase[32];
	int pageNum[100];
};

int main(){
	
	int i,page;
	char inputStr[32];
	bool flag;
	struct book_info index[101]={'\0',0};
	
	memset(inputStr,'\0',sizeof(inputStr));
	
	
	//入力
	for(i=0;i<100;i++){
		
		if(scanf("%s %d",inputStr,&page)==EOF){
			break;
		}
		
		flag=true;
		
		//入力済みの単語かどうかを調べる
		int j;
		for(j=0;j<i;j++){
			//入力済みなら
			if(strcmp(index[j].phrase,inputStr)==0){
				//ページ番号の記憶
				for(int k=0;k<100;k++){
					if(index[j].pageNum[k]==0){
						index[j].pageNum[k]=page;
						break;
					}
				}
				
				flag=false;
				break;
			}
		}
		
		//入力されてないなら
		if(flag){
				strcpy(index[j+1].phrase,inputStr);
				index[j+1].pageNum[0]=page;
		}
		
		memset(inputStr,'\0',sizeof(inputStr));
	}
	
	
	//単語昇順バブルソート
	for(int j=0;j<i;j++){
		for(int k=i-1;k>j;k--){
			if(strcmp(index[k-1].phrase,index[k].phrase)>0){
				   struct book_info temp;
				   temp=index[k];
				   index[k]=index[k-1];
				   index[k-1]=temp;				
			}
		}
	}
	
	//単語昇順かつページ番号昇順バブルソート
	for(int g=0;g<i;g++){
		for(int j=0;j<101 && index[g].pageNum[j]!=0;j++){
			for(int k=i-1;k>j;k--){
				if((index[g].pageNum[k-1]>index[g].pageNum[k]) && 
				    index[g].pageNum[k-1]!=0 &&
				    index[g].pageNum[k]!=0){		
						int temp;
						temp=index[g].pageNum[k];
						index[g].pageNum[k]=index[g].pageNum[k-1];
						index[g].pageNum[k-1]=temp;				
				}
			}
		}
	}
	
	for(int j=0;j<i;j++){
		if(index[j].phrase[0]!='\0'){
			cout<<index[j].phrase<<endl;
		}
		for(int k=0;k<101 && index[j].pageNum[k]!=0;k++){
			if(index[j].pageNum[k+1]!=0){
				cout<<index[j].pageNum[k]<<" ";
			}else{
				cout<<index[j].pageNum[k]<<endl;
			}
		}
	}
}

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

int main(int argc, char const *argv[])
{
	map<string, vector<int> > index;
	string s;
	int n;
	while(cin>>s>>n){
		index[s].push_back(n);
		sort(index[s].begin(),index[s].end());
	}

	map<string,vector<int> >::const_iterator it;
	vector<int>::const_iterator it2;
	for(it=index.begin(); it!=index.end();it++){
		cout<<(*it).first<<endl;
		for(it2=(*it).second.begin();it2!=(*it).second.end()-1;it2++){
			cout<<(*it2)<<" ";
		}
		cout<<(*it2)<<endl;
	}
	return 0;
}

C++: /*
	0105:book Index
*/
#include	<iostream>
#include	<vector>
#include	<utility>
#include	<string>

using namespace std;

typedef pair<string, int> P_SI;

int main(void) {
	string memstr = " ";
	vector<P_SI> words;
	
	while(1) {
		string buf_s;
		int buf_i;
		
		cin >> buf_s >> buf_i;
		if(cin.eof()) { break; }
		words.push_back( P_SI(buf_s, buf_i) );
	}
	sort( words.begin(), words.end() );
	
	vector<P_SI>::iterator it = words.begin();
	bool isFirst = true;
	while( it != words.end() ) {
		string buf_s = (*it).first;
		int buf_i = (*it).second;
		
		if(buf_s != memstr) {
			if(it != words.begin()) {
				cout << endl;
			}
			cout << buf_s << endl;
			memstr = buf_s;
			isFirst = true;
		}
		if(isFirst) {
			cout << buf_i;
			isFirst = false;
		} else {
			cout << ' ' << buf_i;
		}
		it++;
	}
	cout << endl;
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
pair<string,int> d[101];
int r[101];
int p[101][101];
int main(){
	string a;
	int q,t;
	t=0;
	while(cin>>a>>q){
		bool news=true;
		for(int i=0;i<t;i++){
			if(d[i].first==a){
				p[i][r[i]]=q;
				r[i]++;
				news=false;
			}
		}
		if(news){
			d[t].first=a;
			d[t].second=t;
			r[t]=1;
			p[t][0]=q;
			t++;
		}
	}
	sort(d,d+t);
	for(int i=0;i<t;i++)sort(p[i],p[i]+r[i]);
	for(int i=0;i<t;i++){
		int y=d[i].second;
		cout<<d[i].first<<endl<<p[y][0];
		for(int j=1;j<r[y];j++)cout<<" "<<p[y][j];
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>

using namespace std;

int find(vector <string>::iterator it, string s, int n);

int main() {
    string s;
    int n;
    map< string, priority_queue<int, vector<int>, greater<int> > > index;
    vector<string> word;

    while (1) {
        cin >> s;
        if(cin.eof()) break;
        cin >> n;

        index[s].push(n);
        if(find(word.begin(), s, word.size()) == -1) {
            word.push_back(s);
        }
    }

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

    vector <string>::iterator it = word.begin();
    while (it != word.end()) {
        cout << *it << endl;
        while (index[*it].size() > 1) {
            cout << index[*it].top() << " ";
            index[*it].pop();
        }
        cout << index[*it].top() << endl;
        it++;
    }

    return 0;
}

int find(vector <string>::iterator it, string s, int n) {
    for (int i=0; i<n; i++, it++) {
        if (*it == s) {
            return i;
        }
    }

    return -1;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	map < string, vector<int> > index;

	string sbuf;
	int ibuf;

	while (cin>>sbuf>>ibuf)
	{
		index[sbuf].push_back(ibuf);
	}

	for (auto &elem : index)
	{
		sort(elem.second.begin(), elem.second.end());
		cout << elem.first << endl;
		for (auto &vecElem : elem.second)
		{
			cout << vecElem << " ";
		}
		cout <<"\b"<< endl;
	}

	return 0;
}