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<map>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	map < string, vector<int> > p;
	string s;
	int page;
	while (cin >> s >> page){
		pair<string, int>pa;
		p[s].push_back(page);
	}
	map<string, vector<int>>::iterator it;
	for (it = p.begin(); it != p.end(); it++){
		sort(p[(*it).first].begin(), p[(*it).first].end());
		cout <<(*it).first << endl;
		for (int i = 0; i < (*it).second.size(); i++){
			if (i == (*it).second.size() - 1){
				cout << p[(*it).first][i];
				break;
			}
			cout << p[(*it).first][i] << " ";
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    pair<string, int> t[1010];
    int i;
    for(i=0; cin >> t[i].first >> t[i].second; i++);
    sort(t, t+i);
    cout << t[0].first << "\n";
    cout << t[1].second;
    for(int j=1; j<i; j++){
        if(t[j-1].first==t[j].first){
            cout << " " << t[j].second;
        }
        else{
            cout << "\n";
            cout << t[j].first << "\n";
            cout << t[j].second;
        }
    }
    cout << "\n";
}

C++: #include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page, page_count;
 
    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;
        page_count=0;
        sort(book.second.begin(), book.second.end());
        for (int page : book.second){
            if (page_count) cout<<" "<<page;
            else cout<<page;
            page_count++;
        }
        cout<<'\n';
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  vector<string> a(100);
  vector<int> b(100);
  int i=0;
  while(cin>>a[i]>>b[i])i++;

  rep(k,i){
    rep(j,i-1){
      if(a[j]>a[j+1]){
	swap(a[j],a[j+1]);
	swap(b[j],b[j+1]);
      }
      if(a[j]==a[j+1]&&b[j]>b[j+1])
	swap(b[j],b[j+1]);
    }
  }


  rep(j,i){
    if(j&&a[j]==a[j-1])cout<<" "<<b[j];
    else cout<<a[j]<<endl<<b[j];
    if(j-i+1&&a[j]!=a[j+1])cout<<endl;
  }
  cout<<endl;
}

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

map<string, vector<int> > book_index;

int main(void){
  string name;
  int page;
  while(cin >> name >> page){
    book_index[name].push_back(page);
  }

  for(auto word : book_index){
    cout << word.first << endl;
    sort(word.second.begin(), word.second.end());
    for(int i = 0; i < word.second.size(); i++){
      cout << word.second[i];
      if(i < word.second.size() - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
class data{
public:
  string words;  
  int page;
  bool operator < (const data& s)const{
    if(words < s.words) return true;
    else if(words > s.words) return false;
    else{
      if(page < s.page) return true;
      else return false;
    }
  }
};
int main(){
  int i=0;
  data in[1000];
  while(1){
    in[i].words="";
    char c;
    if(scanf("%c", &c)==EOF) break;
    in[i].words+=c;
    for(int j=1;;j++){
      scanf("%c", &c);
      if(c==' ') break;
      in[i].words+=c;
    }
    cin >> in[i].page;
    getchar();
    i++;
  }
  
  sort(in,in+i);

  cout << in[0].words << endl << in[0].page;
  for(int j=1;j<i;j++){
    if(in[j-1].words != in[j].words){
      cout << endl;
      cout << in[j].words << endl << in[j].page;
    }
    else{
      cout << ' ' << in[j].page;
    }
  }
  cout << endl;
  return 0;
}

C++: #pragma warning(disable:4996)
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;

int main(){
	string word;
	int page;
	map<string, set<int>> indexs;
	while (cin >> word >> page){
		indexs[word].insert(page);
	}
	for (auto index : indexs){
		cout << index.first << endl;
		for (auto page_a : index.second){
			cout << page_a<<" ";
		}
		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;j++){
			for(int k=101-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 <set>

using namespace std;

typedef map<string, set<int>> Dic;
Dic dic;

int main(){
  //map<string, int> dic;
  int num;
  string s;
  while(cin >> s >> num)
  {
    dic[s].insert(num);
  }
  
  for(Dic::iterator it = dic.begin() ; it != dic.end() ; it++)
  {
  	cout << it->first << endl;
  	for(set<int>::iterator set_it = it->second.begin() ; set_it != it->second.end() ; set_it++)
  	{
  		cout << *set_it << " ";
  	}
  	cout << endl;
  }

  return 0;
}