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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	string str;
	vector< pair<string,int> >sp;
	int num;
	while(cin>>str>>num){
		sp.PB(MP(str,num));
	}
	bool c=false;
	SORT(sp);
	REP(i,SZ(sp)){
		if(!c)cout<<sp[i].first<<endl;
		if(i!=SZ(sp)-1&&sp[i].first==sp[i+1].first){
			cout<<sp[i].second<<" ";
			c=true;
		}else{
			c=false;
			cout<<sp[i].second<<endl;
		}
		
	}
	return 0;
}

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

int main() {
  string s;
  int p;
  map<string,set<int> > m;
  while(cin >> s >> p) {
    m[s].insert(p);
  }
  for(map<string,set<int> >::iterator i = m.begin();
      i != m.end(); ++i) {
    cout << i->first;
    for(set<int>::iterator j = i->second.begin();
        j != i->second.end(); ++j) {
      cout << " " << *j;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <map>
#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
using namespace std;
typedef priority_queue< int,vector<int>,greater<int> > myqueue;

int main()
{
	myqueue que;
	map< string,myqueue > index;
	map< string,myqueue >::iterator it;
	int paz;
	char in[1001];
	string word;

	while( scanf("%s %d",in,&paz) != EOF ){
		word.append(in);
		
		if( index.find(word) == index.end() ){
			que.push(paz);
			index.insert( make_pair(word,que) );
			que.pop();
		}
		
		else{
			index[word].push(paz);
		}

		word.erase( word.begin(),word.end() );
	}

	for(it = index.begin(); it != index.end(); it++){
		cout << it->first << endl;
		while( !it->second.empty() ){
			printf("%d",it->second.top());
			it->second.pop();
			if(it->second.empty()){
				printf("\n");
			}
			else{
				printf(" ");
			}
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 20000000
map<string,vector<int> > book;
int main()
{
        string s;
        int page;
        while(cin >> s >> page)
        {
                book[s].pb(page);
        }
        for(map<string,vector<int> >::iterator it=book.begin();it!=book.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];
                        if(i==((it->second.size())-1))
                        {
                                cout << endl;
                        }
                        else
                        {
                                cout << ' ';
                        }
                }
        }
        return 0;
}

C++: int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,p!=0){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::vector<int> v = (*m_it).second;
    std::sort(v.begin(),v.end());
    std::vector<int>::iterator v_it = v.begin();
    while(v_it!=v.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==v.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}

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

#define out cout 
#define in cin
#define el endl

#define rep(i, N) for (int i = 0; i < N; i++)
#define ol(N) cout << N << endl

int main()
{
	int a, c = 0;
	string s;
	map<string, vector<int>> m;

	while (in >> s >> a){
		m[s].push_back(a);
	}
	for (auto chie : m) {
		cout << chie.first << '\n';
		sort(chie.second.begin(), chie.second.end());
		rep(i, chie.second.size() - 1) {
			cout << chie.second[i] << " ";
		}
		cout << chie.second[chie.second.size() - 1] << '\n';
	}

	return (0);
}

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

using namespace std;

int main() {
    map<string, vector<int> > pages;
    string word;
    int page;

    while(cin>>word>>page) {
        pages[word].push_back(page);
    }

    for(auto& e : pages) {
        sort(e.second.begin(), e.second.end());
    }

    for(auto& e :pages) {
        cout<<e.first<<endl;
        for(auto& v: e.second) {
            cout<<v<<" ";
        }
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;pair<string,int> a[100];int main(){int t=0,g,i;while(cin>>a[t].first>>a[t].second)t++;sort(a,a+t);string f,b=a[0].first;cout<<b<<endl<<a[0].second;for(i=1;i<t;i++){bool n=0;f=a[i].first,g=a[i].second;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<size-1i++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;
  }
}