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 <vector>
#include <list>
#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>
#include <cassert>
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)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	map<string,vi> se;
	string s;
	while(cin>>s){
		int n;
		cin>>n;
		if(!EXIST(se,s)){
			se[s]=vi();
		}
		se[s].push_back(n);
	}
	for(map<string,vi>::iterator it=se.begin();it!=se.end();it++){
		cout<<(*it).first<<endl;
		REP(i,(*it).second.size()){
			cout<<(i==0?"":" ")<<(*it).second[i];
		}
		cout<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<map>
#include<set>

using namespace std;

int main(void){
  std::ios_base::sync_with_stdio();
  
  multimap<string,int> indexs;
  set<int> indexn;
  set<int>::iterator ites;
  map<string,int>::iterator item;
  string inps,tmps;
  int inpi;

  while(cin>>inps>>inpi){
	  indexs.insert(map<string,int>::value_type(inps,inpi));
  }
   item=indexs.begin();
	  tmps=(*item).first;
	  cout<<tmps<<endl;
	  while(indexs.end()!=item){
		  if(tmps!=(*item).first){
			  ites=indexn.begin();
			  while(indexn.end()!=ites){
				  cout<<(*ites);
				  ites++;
				  if(indexn.end()==ites) cout<<endl;
				  else cout<<" ";
			  }
			  tmps=(*item).first;
			  cout<<tmps<<endl;
			  indexn.clear();
		  }
		  indexn.insert((*item).second);
		  item++;
	  }
	  ites=indexn.begin();
	  while(indexn.end()!=ites){
			cout<<(*ites);
			ites++;
			if(indexn.end()==ites) cout<<endl;
			else cout<<" ";
	  }
	  indexn.clear();
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    map<string,vector<int>> ans;
    string s;
    while(cin>>s){
        int t; cin>>t;
        ans[s].push_back(t);
    }
    
    for(auto itr=ans.begin();itr!=ans.end();itr++){
        vector<int> t=itr->second;
        REP(i,t.size()-1)cout<<t[i]<<" ";
        cout<<t[t.size()-1]<<endl;
    }
    
    return 0;
}

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

using namespace std;

string itos(int);


int main(){


  string s[1000];
  int n[1000];

  int sumin = 0;


  for(int i = 0; cin >> s[i] >> n[i]; i++){
    sumin++;
  }

  for(int i = 0; i < sumin-1; i++){
    for(int j = i; j < sumin; j++){
      if(n[i] > n[j]){
        int stock = n[i];
	n[i] = n[j];
	n[j] = stock;
	string stack = s[i];
	s[i] = s[j];
	s[j] = stack;
      }
    }
  }


  string num[1000];


  map<string, string> M;


  for(int i = 0; i < sumin; i++){
    for(int j = 0; j < i; j++){
      if(s[j] == s[i]){
	M[s[i]] += " ";
	break;
      }
    }

    M[s[i]] += itos(n[i]);

  }

  sort(s, s+sumin);


  for(int i = 0; i < sumin-1; i++){
    int check = 0;
    if(i != 0){
      for(int j = 0; j < i; j++){
	if(s[i] == s[j]){
	  check++;
	}else if(check == 0 && j == i-1){	
	  cout << s[i] << endl << M[s[i]] << endl;
	}
      }
    }else{
      cout << s[i] << endl << M[s[i]] << endl;
    }
  }


  
  return 0;
}

string itos(int x){
  ostringstream s;
  s << x;
  return s.str();
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct Info{
	Info(){
		num_of_page = 0;
	}

	void insert(int arg_page){
		page[num_of_page++] = arg_page;
	}

	void sort(){
		if(num_of_page > 0){
			for(int i=1; i <= num_of_page-1; i++){
				for(int k=num_of_page-1; k >= i; k--){
					if(page[k] < page[k-1])swap(page[k],page[k-1]);
				}
			}
		}
	}

	void print(){
		printf("%d",page[0]);
		for(int i=1; i < num_of_page; i++)printf(" %d",page[i]);
		printf("\n");

	}

	char word[31];
	int page[100],num_of_page;
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}

	if(left[i] == '\0')return 1;
	else{
		return 2;
	}

}


int main(){

	Info info[100];
	int num_of_info = 0,page;
	bool FLG;

	char buf[31];

	while(scanf("%s %d",buf,&page)!=EOF){
		FLG = false;
		for(int i=0; i < num_of_info; i++){
			if(strCmp(buf,info[i].word)){
				info[i].insert(page);
				FLG = true;
				break;
			}
		}
		if(!FLG){
			strcpy(info[num_of_info].word,buf);
			info[num_of_info].insert(page);
			num_of_info++;
		}
	}

	for(int i=0; i < num_of_info; i++)info[i].sort();

	for(int i=1; i <= num_of_info-1; i++){
		for(int k=num_of_info-1;k >= i; k--){
			if(strCmp2(info[k].word,info[k-1].word) == 1)swap(info[k],info[k-1]);
		}
	}

	for(int i=0; i < num_of_info; i++){
		printf("%s\n",info[i].word);
		info[i].print();
	}


    return 0;
}