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

int main()
{
  string word;
  int page;
  map<string, vector<int> > index;
  while (cin >> word >> page)
    index[word].push_back(page);

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

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

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    std::map<std::string, std::vector<int>> mp;
    std::string s;
    int p;
    while (std::cin >> s >> p) { mp[s].push_back(p); }

    for (auto m : mp) {
        std::cout << m.first << std::endl;
        std::sort(m.second.begin(), m.second.end());
        int c = 0;
        for (auto x : m.second) {
            if (c++ == 0)
                std::cout << x;
            else
                std::cout << ' ' << x;
        }
        std::cout << std::endl;
    }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	map < string, vector<int> > index;

	string sbuf;
	int ibuf;

	while (cin>>sbuf>>ibuf)
	{
		index[sbuf].push_back(ibuf);
	}

	for (auto &elem : index)
	{
		sort(elem.second.begin(), elem.second.end());
		cout << elem.first << endl;
		for (auto vecElem : elem.second)
		{
			cout << vecElem << " ";
		}
		cout <<"\b"<< endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int main() {
	map<string, vector<int> > D;
	string w;
	int n;
	while(cin >> w >> n) {
		D[w].push_back(n);
	}
	map<string, vector<int> >::iterator it = D.begin();
	for(; it != D.end(); it++) {
		cout << it->first << endl;
		int size = it->second.size();
		sort(it->second.begin(),it->second.end());
		for(int i = 0; i < size - 1; i++){
			cout << it->second[i] << " ";
		}
		cout << it->second[size-1] << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	string str;
	ll p;
	map<string, priority_queue<ll, vector<ll>, greater<ll>>>mp;
	while (cin >> str >> p) {
		mp[str].push(p);
	}
	REPC(i, mp) {
		cout << i.first << endl;
		REP(j, i.second.size()) {
			if (j != 0)cout << ' ';
			cout << i.second.top();
			i.second.pop();
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
pair<string,int> d[101];int r[101],p[101][101],q,t=0;
int main(){string a;while(cin>>a>>q){bool news=true;for(int i=0;i<t;i++){if(d[i].first==a){p[i][r[i]]=q;r[i]++;news=false;}}if(news){d[t].first=a;d[t].second=t;r[t]=1;p[t][0]=q;t++;}}sort(d,d+t);for(int i=0;i<t;i++)sort(p[i],p[i]+r[i]);for(int i=0;i<t;i++){int y=d[i].second;cout<<d[i].first<<endl<<p[y][0];for(int j=1;j<r[y];j++)cout<<" "<<p[y][j];cout<<endl;}return 0;}

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

using namespace std;

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

int main(){
  
  Data a[100000];
  int n=0;
  string str;
  int id;
  while( cin>>str>>id ){
    a[n]= (Data){ str, id };
    n++;
  }
  sort(a,a+n);

  string key="";
  
  for(int 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].num;
    }else{
      cout<<' '<<a[i].num;
    }
  }

  cout<<endl;
  
  return 0;
}

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

int main(){
  pair< string ,int > book[1001];
  string name;
  int n=0 ,num;
  bool flag=true;
  while( cin >> name >> num ){
    book[n].first  = name;
    book[n].second = num;
    n++;
  }

  sort( book ,book+n );
  for( int i=0 ; i<n ; i++ ){
    for( int j=0 ; j<n ; j++ ){
      if( i != j && book[i].first.find(book[j].first) != string::npos ){
	book[j].first = ' ';
      }
    }
  }
  for( int i=0 ; i<n ; i++ ){
    if( book[i].first.compare( " " ) == 0 )
      cout << ' ' << book[i].second;
    else{
      if( !i ){
	cout << book[i].first << endl << book[i].second;
	flag = true;
      }
      else{
	cout << endl << book[i].first << endl << book[i].second;
	flag = false;
      }
    }
  }
  if( !flag ) cout << endl;
}

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

int main(){
  string phrase;
  int page;
  map<string, set<int> > dictionary;

  while(cin >> phrase >> page){
    //cin >> phrase >> page;
    // if(phrase == "end") break;
    dictionary[phrase].insert(page);
  }

  map<string, set<int> >::iterator p1;
  set<int>::iterator p2;

  for(p1 = dictionary.begin(); p1 != dictionary.end(); p1++){
    cout << (*p1).first << endl;

    p2 = dictionary[(*p1).first].begin();
    cout << *p2;
    for( p2++; p2 != dictionary[(*p1).first].end(); p2++){
      cout << " " << *p2;
    }
    cout << endl;

  } 

  return 0;
}