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 <bits/stdc++.h>
using namespace std;

int main() {
    string word;
    map<string, set<int>> m;
    while(cin >> word) {
        int page;
        cin >> page;
        m[word].insert(page);
    }
    for(auto& p : m) {
        cout << p.first << endl;
        for(auto it = p.second.begin(); it != p.second.end(); ++it) {
            if(it != p.second.begin()) {
                cout << ' ';
            }
            cout << *it;
        }
        cout << endl;
    }
}

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

using namespace std;

int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page;

    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }

    for (auto& book : books){
        cout<<book.first<<endl;

        sort(book.second.begin(), book.second.end());

        for (const auto& page : book.second){
            cout<<page<<" ";
        }
        cout<<'\n';
    }
    return 0;
}

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

struct Data{
  string name;
  int page;

  bool operator < (const Data &data)const{
    if(name==data.name){
      if(page<data.page) return true;
      else return false;
    }else{
      if(name<data.name) return true;
      else return false;
    }
  }
};

int main(){

  Data a[110];
  string s;
  int n, i=0;

  while(cin>>s>>n){
    a[i]=(Data){s, n};
    i++;
  }

  sort(a, a+i);

  string key="";

  n=i;
  for(i=0;i<n;i++){
    if(key!=a[i].name){
      key=a[i].name;
      if(i>0){
	cout<<endl;
      }
      cout<<key<<endl;
      cout<<a[i].page;
    }else{
      cout<<" "<<a[i].page;
    }
  }

  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]<<" ";
		}
		cout<<endl;
	}
	/*
	fflush(stdin);
	getchar();
	*/
	return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;int main(){string s;int n;map<string,set<int> >z;map<string, set<int> >::iterator q;set<int>::iterator x;while(cin>>s>>n)z[s].insert(n);for(q=z.begin();q!=z.end();){s=q++->first;cout<<s<<endl;for(x=z[s].begin(),n=0;x!=z[s].end();){if(n++)cout<<" ";cout<<*x++;}cout<<endl;}return 0;}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int dp[101][101];
int num[101][101];
bool comp(string a,string b){
	for(int i=0;i<min(a.size(),b.size());i++){
		if(a[i]-'a'<b[i]-'a'){
			return true;
		}else if(b[i]-'a'<a[i]-'a'){
			return false;
		}
	}
	return a.size()<b.size();
}
map<string,vector<int> >ma;
int main(){
	int cou=0;
	string str;
	int n;
	while( cin >> str !='\0'){
		scanf("%d",&n);
		ma[str].push_back(n);
	}
	map<string,vector<int> >::iterator ite;
	for(ite=ma.begin();ite!=ma.end();++ite){
		cout << ite->first << endl;
		vector<int>yu=ite->second;
		cout << yu[0];
		for(int i=1;i<yu.size();i++){
			cout <<" " << yu[i];
		}
		cout << endl;
	}
}

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

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

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(), 
		      [](const Index& x, const Index& y) { return x.word < y.word;});

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

	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()){
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAX = 1000;

typedef pair<string, vector<int> > pp;

int main()
{
    string s;
    int n;
    vector<pp> ind;
    vector<int> emp;

    while(cin >> s >> n)
    {
        bool found = false;
        REP(ind.size() )if(ind[i].first == s){ ind[i].second.push_back(n); found = true; break; }
        if(found)continue;

        ind.push_back(pp(s,emp));
        ind[ind.size() - 1].second.push_back(n);
    }
    sort(all(ind));


    REP(ind.size())
    {
        //sort(ind[i].second.begin(), ind[i].second.end());
        sort(all(ind[i].second));
        cout << ind[i].first << endl;
        rep(j, ind[i].second.size())
        {
            cout << ind[i].second[j] ;
            if(j == ind[i].second.size() - 1) break;
            cout << " " ;
        }

        cout << endl ;
    }
    return 0;
}

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

string str;
int n;

map<string, vector<int> > dict;

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

C++: #include <iostream>
#include <map>
#include <string>
#include <set>

using namespace std;

int main(){
	int n;
	string str;	
	map<string, set<int> > m;

	while(cin >> str >> n){
		m[str].insert(n);
	}
	for(auto it = m.begin(); it != m.end(); it++){
		cout << it->first << endl;
		for(auto its =  it->second.begin(); its != it->second.end(); its++){
			cout << *its << " ";
		}
		cout << endl;
	}
}