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<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	map < string, vector<int> > index;

	char cbuf[31];
	int ibuf;

	while (scanf_s("%s %d", cbuf, 31, &ibuf) != EOF)
	{
		index[cbuf].push_back(ibuf);
	}

	for (auto &elem : index)
	{
		sort(elem.second.begin(), elem.second.end());
		printf_s("%s\n", elem.first.c_str());
		for (auto &vecElem : elem.second)
		{
			printf_s("%d ", vecElem);
		}
		printf_s("\n");
	}

	return 0;
}

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

struct dic{
	string s;
	int page[1001];
};

int comp(const void *a, const void *b){
if(((dic*)a)->s > ((dic*)b)->s) return 1;
else return -1;
}

int main(void){
	int i,j,p,tail=0;
	string str;
	dic d[100];
	memset(d, 0, sizeof(d));
int count=0;
while(count++<100){
		cin >> str;
		for(i=0;i<tail;i++){
			if(str == d[i].s){
				cin >> p;
				d[i].page[p]=1;
				break;
			}
		}
		if(i == tail){
			d[tail].s = str;
			cin >> p;
			d[tail].page[p]=1;
			tail++;
		}
	}

	qsort(&d,tail,sizeof(dic),comp);
	int f=0;
	for(i=0;i<tail;i++){
		f=0;
		cout << d[i].s << endl;
		for(j=0;j<1001;j++){
			if(d[i].page[j] == 1){
				if(f) cout << " " << j;
				else{ cout << j; f++;}
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    pair<string, int> data[100];
    int i = 0;
    while (cin >> data[i].first >> data[i].second) {i++;}
    sort(data, data+i);
    cout << data[0].first << '\n' << data[0].second;
    for (int j = 1; j < i; j++) {
        if (data[j-1].first != data[j].first) {
            cout << '\n' << data[j].first << '\n' << data[j].second;
        } else {
            cout << " " << data[j].second;
        }
    }
    cout << endl;
    return 0;
}

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

class tWord{
public:
	string word;
	vector<int> page;
	tWord( string w );
};
tWord::tWord( string w ){
	word = w;
	page.clear();
}

bool operator<( const tWord &l, const tWord &r ){
	return l.word < r.word;
}

int main(){
	vector<tWord> words;
	string line;
	int n;
	char w[31];

	// input
	while(1){
		getline( cin, line );
		if( line.size()==0 ) break;
		sscanf(line.c_str(), "%s %d", w, &n);
		int i;
		for( i=0; i<words.size(); i++ ){
			if( words[i].word == w ){
				break;
			}
		}
		if( i == words.size() ){
			string ww = w;
			words.push_back(ww);
		}
		words[i].page.push_back(n);
	}

	// output
	sort( words.begin(), words.end() );
	for( int i=0; i<words.size(); i++ ){
		if( words[i].word != "" ){
			cout << words[i].word << endl;
			sort( words[i].page.begin(), words[i].page.end() );
			cout << words[i].page[0];
			for( int j=1; j<words[i].page.size(); j++ ){
				cout << " " << words[i].page[j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

typedef struct{
	std::string word;
	std::vector<int> page;
}Index;

bool operator<(const Index& x, const Index& y) { return x.word < y.word ;}


int main(void){
	int i, page;
	std::string word;

	std::vector<Index> Books;

	int NoW = 0;
	while(std::cin >> word >> page){
		for(i=0;i<NoW;i++){
			if(Books[i].word==word){
				Books[i].page.insert(Books[i].page.end(), page);
				break;
			}
		}
		if(i==NoW){
			Index temp;
			temp.word = word;
			temp.page.insert(temp.page.begin(), page);
			Books.insert(Books.end(), temp);
			NoW++;
		}
	}
	
	std::sort(Books.begin(), Books.end());

	for(unsigned int i=0;i<Books.size();i++){
		std::sort(Books[i].page.begin(), Books[i].page.end());
	}

	for(unsigned int i=0;i<Books.size();i++){
		std::cout << Books[i].word << std::endl;
		for(unsigned int j=0;j<Books[i].page.size();j++){
			std::cout << Books[i].page[j];
			if(j!=Books[i].page.size()-1){
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}

	return 0;
}

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

int main(int argc, char const* argv[])
{
	std::map<std::string,std::vector<unsigned>> index;
	std::vector<std::string> words;
	std::string word;
	unsigned page;
	while (std::cin >> word >> page) {
		if (index[word].size()==0)
			words.push_back(word);
		index[word].push_back(page);
	}
	std::sort(words.begin(),words.end());
	for (auto& s : words) {
		std::cout << s << std::endl;
		auto& cindex = index[s];
		std::sort(cindex.begin(),cindex.end());
		bool b{false};
		for (auto& p : cindex) {
			if (b) {
				std::cout << ' ';
			}
			b = true;
			std::cout << p ;
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>

using namespace std;


string w,p;


int main(){
    map<string, string> book;
    
    while(cin>>w>>p){
        if(book.find(w)==book.end()){
            book[w]=p;
        }else{
            book[w]=book[w]+" "+p;
        }
    }
    
    for (map<string, string>::iterator itr = book.begin(); itr != book.end(); itr++)
	{
		// キーを出力
		cout << itr->first << endl;
		// 値を出力
		cout << itr->second << endl;
	}
    
}

C++: #include <stdio.h>
#include <iostream>
#include <list>
#include <map>
#include <stdlib.h>

using namespace std;

int main(void)
{
	list<string> strList;
	map<string, list<int> > pages;
	char buf[256];
	char word[256];
	int i;
	
	while (fgets(buf, 256, stdin) != NULL){
		for (i = 0; buf[i] != ' '; i++){
			word[i] = buf[i];
		}
		word[i] = '\0';
		i++;
		strList.push_back(word);
		pages[strList.back()].push_back(atoi(&buf[i]));
	}
	
	strList.sort();
	strList.unique();
	list<string>::iterator it;
	for (it = strList.begin(); it != strList.end(); it++){
		pages[*it].sort();
		list<int>::iterator itt;
		printf("%s\n", it->c_str());
		itt = pages[*it].begin();
		printf("%d", *itt);
		itt++;
		for (; itt != pages[*it].end(); itt++){
			printf(" %d", *itt);
		}
		cout << endl;
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num,page[1000][100]={},nu[1000]={};
    memset(nu,0,sizeof(nu));
    string str[1000],s;
    while(cin>>s>>num){
        for(int i=0;i<sen;i++){
            if(str[i]==s){
                nu[i]++;
                page[i][nu[i]]=num;
                num=0;
                break;
            }
        }
        if(num!=0){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    for(int i=0;i<sen;i++){
        for(int j=0;j<sen;j++)if(str[num]>str[j])num=j;
        cout<<str[num]<<endl;
        str[num]="zzzzzzzzzzzzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num];k>j;k--){
                if(page[num][k]<page[num][k-1]){
                    int kawa=page[num][k-1];
                    page[num][k-1]=page[num][k];
                    page[num][k]=kawa;
                }
            }
        }
        cout<<page[num][0];
        for(int j=1;j<=nu[num];j++)cout<<" "<<page[num][j];
        cout<<endl;
    }
}