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

struct Book{
    string str;
    int num;

    Book(string s,int n){
        str = s;
        num = n;
    }

    Book(){
        str ="";
        num = 0;
    }

    bool operator < (const Book &book) const{
       if(str == book.str){
           if(num < book.num)return true;
           else return false;
       }else{
           if(str < book.str)return true;
           else return false;
       }
    }
};


int main(){


    Book array[10000];

    int cou=0;
    string name;
    int page;

      while(cin >> name >> page){
        array[cou++]=Book(name, page);
    }

    sort(array,array+cou);

    string key="";

    for(int i=0;i<cou;i++){
        Book c = array[i];
        if(key!=c.str){
            key=c.str;
            if(i>0)cout << endl;
            cout << key << endl;
            cout << c.num;
        }else{
            cout << ' ' << c.num;
        }
    }

    cout << endl;
    
}

C++: //
//  main.cpp
//  main
//
//  Created by h3037175 on 2018/01/25.
//  Copyright © 2018年 h3037175. All rights reserved.
//

#include <iostream>
#include<string>
#include<utility>
using namespace std;
int main() {
    pair<string,int> go[100000];
    int i=0;
    while(cin>>go[i].first>>go[i].second){
        i++;
        
    }
    int at;
    string fir;
    at=0;
    for(int l=0;l<i;++l){
        fir="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
        for(int j=l;j<i;++j){
            if(go[j].first<=fir){
                fir=go[j].first;
                at=j;
            }
        }
        swap(go[at],go[l]);
    }
    
    string num="";
    fir=go[0].first;
    for(int k=1;k<i;++k){
        if(go[k].first!=fir){
        fir=go[k].first;
        }
        else{
            go[k].first="-1";
        }
    }
    for(int k=0;k<i;++k){
        if(go[k].first=="-1"){
            cout<<" "<<go[k].second;
        }
        else{
            cout<<endl<<go[k].first<<endl<<go[k].second;
        }
    }
    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()){
				std::cout << " ";
			}
		}
		std::cout << std::endl;
	}

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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	string s;
	map<int, string> table;
	vs name;
	vi page;

	while(cin >> s) {
		int p;
		cin >> p;
		name.push_back(s);
		page.push_back(p);
		table[p] = s;
	}

	sort(ALL(name));
	sort(ALL(page));
	
	set<string> names;
	REP(i, name.size()) {
		names.insert(name[i]);
	}

	set<string>::iterator it = names.begin();
	while(it != names.end()) {
		cout << *it << endl;
		bool flag = false;
		REP(i, page.size()) {
			if(table[page[i]] == *it) {
				if(flag) {
					cout << " ";
				}
				cout << page[i];
				flag = true;
			}
		}
		cout << endl;
		++it;
	}

	return 0;
}

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(auto itt:it.second){
            cout<<itt<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}

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

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

dic d[101];

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;
while((cin >> str) != NULL){
		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;
	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<algorithm>
#include<vector>
#include<map>
using namespace std;

int main(){

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

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

  for(auto p:mp){
    string name=p.first;
    vector<int> v=p.second;

    cout<<name<<endl;

    sort(v.begin(), v.end());
    for(int i=0;i<(int)v.size();i++){
      if(i>0) cout<<" ";
      cout<<v[i];
    }

    cout<<endl;
  }
  
  return 0;
}