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 <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class cob{
public:
	string str;
	vector<int> num;
	cob(string str):str(str){}

	bool operator < (const cob &ano){
		return str < ano.str;
	}

	void S()
	{
		sort(num.begin(), num.end());
	}
};



int main(void)
{
	string instr;
	int num;
	vector<cob> index;

	bool f = false;
	while(cin >> instr >> num, !cin.eof()){
		for(int i = 0; i < index.size(); i++){
			if(index[i].str == instr){			
				index[i].num.push_back(num);
				f = true;
				break;
			}
		}
		if(!f){
			index.push_back(cob(instr));
			index.back().num.push_back(num);
		}
	}

	sort(index.begin(), index.end() );
	for(int i = 0; i < index.size(); i++){
		index[i].S();

		cout << index[i].str << endl;
		cout << index[i].num[0];
		for(int j = 1; j < index[i].num.size(); j++)
			cout << ' ' << index[i].num[j];
		cout << endl;
	}

	return 0;
}

C++: //Book Index
#include<bits/stdc++.h>
using namespace std;

map<string, vector<int> > mp;

int main(){
  string s;
  int n;
  while(cin>>s>>n){
    if(mp.find(s)==mp.end()){
      vector<int> tmp;
      tmp.push_back(n);
      mp.insert(map<string, vector<int> >::value_type(s, tmp));
    }
    else{
      mp[s].push_back(n);
    }
  }
  for(map<string, vector<int> >::iterator it=mp.begin(); it!=mp.end(); it++){
    cout<<it->first<<endl;
    sort(it->second.begin(), it->second.end());
    for(int i=0; i<it->second.size(); i++){
      if(i!=it->second.size()-1)cout<<it->second[i]<<' ';
      else cout<<it->second[i]<<endl;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  string str;
  string s[102];
  int n;
  map<string,vector<int> > word;
  int i=0;
  
  while(cin>>str>>n){
    if(!word.count(str)){
      word[str].push_back(n);
      s[i]=str;
      i++;
    }
    else word[str].push_back(n);
  }
  
  for(int cnt=0;cnt<i;cnt++){
    sort(word[s[cnt]].begin(),word[s[cnt]].end());
    for(int j=0;j<i-1;j++){
      if(s[j]>s[j+1])swap(s[j],s[j+1]);
    }
  }

  for(int cnt=0;cnt<i;cnt++){
    cout<<s[cnt]<<endl;
    for(int j=0;j<word[s[cnt]].size();j++){
      if(j)cout<<" ";
      cout<<word[s[cnt]][j];
    }
    cout<<endl;
  }

  return(0);
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main(){
    map<string,vector<int> >M;
    string str;
    int p;
    while(cin>>str>>p){
        M[str].push_back(p);
    }
    map<string,vector<int> >::iterator ite=M.begin();
    for(;ite!=M.end();ite++){
        sort((ite->second).begin(),(ite->second).end());
    }
    for(ite=M.begin();ite!=M.end();ite++){
        cout<<ite->first<<endl;
        bool f=false;
        for(int i=0;i<(ite->second).size();i++){
            if(f)cout<<" ";
            cout<<(ite->second)[i];
            f=true;
        }
        cout<<endl;
    }
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include    <iomanip>
#include    <map>
#include    <set>
#include    <deque>
#include    <vector>
#include    <stack>
using namespace std;
template <class X>
void prr(X test) {
    for(auto it:test){
        cout<<it;
    }
    cout<<endl;
}
int main(){
    map<string, set<int>> ma;
    string a;
    int aa;
    vector<int> b;
    while((cin>>a >>aa)&&(a!="0")){
        ma[a].insert(aa);
    }
    
    for(auto it:ma){
        cout<<it.first<<endl;
        for (set<int>::iterator itt=it.second.begin();itt!=it.second.end();itt++) {
            cout<<*itt;
            if (itt!=it.second.end().operator--()) {
                cout<<" ";
            }
        }
        cout<<endl;
    }
    
    return 0;
}

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

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;
  	int counter = 0;
  	for(set<int>::iterator set_it = it->second.begin() ; set_it != it->second.end() ; set_it++)
  	{
  		if(counter!=0)cout <<" ";
  		cout << *set_it;
  	}
  	cout << endl;
  }

  return 0;
}

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

using namespace std;

int main(void){

  map <string , vector<int > > m;
  string s;
  int n;

  while( cin >> s >> n ){
    m[s].push_back(n);
  }

  map<string , vector<int> >::iterator it;
  for( it = m.begin() ; it != m.end() ; it++ ){
    cout << it->first << endl;
    sort(it -> second.begin() , it -> second.end() );
    int i;
    for( i = 0 ; i < it -> second.size() - 1 ; i++ ){
      cout << it -> second[i] << " ";
    }
    cout << it -> second[i] << endl;
  }
  return 0;
}

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

//ツつアツづ個偲ィツづ個姪「ツ妥ィツづ? ツ連ツ想ツ配ツ療アツづーツ使ツつ、ツづ?氾アツ湘ュツづ可嘉ーツつォツづ「ツつキツつ「ツづ?つキ
map<string,vector<int> > pages;

int main(){
  string s;
  int p;

  while(cin >> s >> p){
    pages[s].push_back(p);
  }

  map<string,vector<int> >::iterator iter;

  //ツマツッツプツづ個イツテツδ?ツタツづ? ツ篠ォツ渉堕篠ョツ渉?づ?要ツ素ツづーツ偲ヲツ督セツつオツづ?つュツづェツづゥツづ個づ?つサツづ個づ慊づ慊δ?ツプツつキツづェツづ篠つ「ツつ「
  for(iter = pages.begin(); iter != pages.end(); iter++){
    string name = iter->first;
    vector<int> v = iter->second;
    sort(v.begin(), v.end());

    cout << name << endl;

    for(int i = 0; i < v.size(); i++){
      if(i != 0) cout << " ";
      cout << v[i];
    }

    cout << endl;
  }
}

C++: #include<cstdio>
#include<algorithm>
#include<functional>
#include<iostream>
#include<string>
#include<vector>
#define F1 first.first
#define F2 first.second
#define F3 second
using namespace std;
typedef pair<string,int> pp;
int main(void)
{
	int i,j,k,num[1001],n,cnt=0;
	string c;
	vector<pp> s;
	while(cin>>c>>n) {
		s.push_back(pp(c,n));
		cnt++;
	}
	sort(s.begin(),s.end());
	for(i=0;i<cnt;i++) {
		if(!i) cout<<s[i].first<<endl<<s[i].second;
		if(i>0) {
			if(s[i-1].first==s[i].first) cout<<" "<<s[i].second;
			else cout<<endl<<s[i].first<<endl<<s[i].second;
		}
	}
	cout<<endl;
}