Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	index := make(map[string]string)
	keys := []string{}
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		if index[l[0]] == "" {
			keys = append(keys, l[0])
		}
		index[l[0]] += l[1] + " "
	}
	sort.Strings(keys)
	for _, k := range keys {
		fmt.Println(k)
		p := strings.Split(strings.TrimRight(index[k], " "), " ")
		pages := []int{}
		for _, v := range p {
			i, _ := strconv.Atoi(v)
			pages = append(pages, i)
		}
		sort.Ints(pages)
		for i, v := range pages {
			if i > 0 {
				fmt.Printf(" ")
			}
			fmt.Printf("%d", v)
		}
		fmt.Println()
	}
}

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

int main()
{
	vector<pair<string, vector<int> > > v = vector<pair<string, vector<int> > >();
	string s;
	int n;
	while (cin >> s >> n)
	{
		int ok = true;
		for (int i = 0; i < v.size(); i++)
		{
			if (v[i].first == s)
			{
				ok = false;
				v[i].second.push_back(n);
			}
		}
		if (ok)
			v.push_back({ s,{n} });
	}
	for (int i = 0; i < v.size(); i++)
		sort(v[i].second.begin(), v[i].second.end());
	for(int i = 0; i < v.size(); i++)
		for (int j = i + 1; j < v.size(); j++)
		{
			if (v[i].first > v[j].first)
			{
				pair<string, vector<int> > r = v[i];
				v[i] = v[j];
				v[j] = r;

			}
		}
	for (int i = 0; i < v.size(); i++)
	{
		cout << v[i].first << endl;
		for (int j = 0; j < v[i].second.size() - 1; j++)
		{
			cout << v[i].second[j] << " ";
		}
		cout << *(v[i].second.end()) << endl;
	}

	return 0;
}

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

using namespace std;

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

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;
	}
    
}