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 <stdio.h>
#include <string.h>

struct data {
  char id[30];
  int stk[100];
  int sp;
} d[1000];

int main() {
  char id[30];
  int val;
  int i, j, k, dp = 0, f, t;
  struct data tmp;
  while (scanf("%s %d", id, &val) != EOF) {
    f = 0;
    for (i = 0; i < dp; i++) {
      if (strcmp(id, d[i].id) == 0) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      d[i].stk[d[i].sp++] = val;
    } else {
      strcpy(d[dp].id, id);
      d[dp].stk[d[dp].sp++] = val;
      dp++;
    }
  }
  for (i = 0; i < dp; i++)
    for (j = dp - 1; j > 0; j--)
      if (strcmp(d[j - 1].id, d[j].id) > 0) {
        tmp = d[j - 1];
        d[j - 1] = d[j];
        d[j] = tmp;
      }
  for (i = 0; i < dp; i++) {
    printf("%s\n", d[i].id);
    for (j = 0; j < d[i].sp; j++)
      for (k = d[i].sp - 1; k > 0; k--)
        if (d[i].stk[k - 1] > d[i].stk[k]) {
          t = d[i].stk[k - 1];
          d[i].stk[k - 1] = d[i].stk[k];
          d[i].stk[k] = t;
        }
    for (j = 0; j < d[i].sp; j++)
      printf("%d ", d[i].stk[j]);
    printf("\n");
  }

  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;
  		counter++;
  	}
  	cout << endl;
  }

  return 0;
}

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

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>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>

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 kbhit(void)
{
    struct termios oldt, newt;
    int ch;
    int oldf;

    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
    fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);

    ch = getchar();

    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    fcntl(STDIN_FILENO, F_SETFL, oldf);

    if (ch != EOF) {
        ungetc(ch, stdin);
        return 1;
    }

    return 0;
}

int main(){
	string str;
	vector<pair<string,int>>sp;
	int cnt=0;
	while(cnt==0||kbhit()){
		getline(cin,str);
		string t1="",t2="";
		int i;
		for(i=0;str[i]!=' ';i++){
			t1+=str[i];
		}
		i++;
		for(;i<SZ(str);i++){
			t2+=str[i];
		}
		int num=toInt(t2);
		sp.PB(MP(t1,num));
		cnt++;
	}
	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<vector>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  map< string , vector<int> > mp;
  
  string str;
  int num;
  
  while( cin>>str>>num ){
    mp[ str ].push_back( num );
  }

  //for( pair<string,vector<int> > p : mp){ 
    string name=p.first;
    vector<int> v=p.second;
    sort(v.begin(),v.end());
    
    cout<<name<<endl;

    for(int i=0;i<(int)v.size();i++){
      if(i>0)cout<<' ';
      cout<<v[i];
    }
    cout<<endl;
  }
  
  return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main(void)
{
	map<string, vector<int> > index;
	vector<string> name;
	string key;
	int page;
	while((cin>>key>>page))
	{
		int flg=0;
		for(int f1=0;f1<name.size();f1++)
		{
			if(name[f1]==key)flg=1;
		}
		if(!flg)name.push_back(key);
		index[key].push_back(page);
	}
	sort(name.begin(),name.end());
	for(int f1=0;f1<name.size();f1++)
	{
		sort(index[name[f1]].begin(),index[name[f1]].end());
		cout<<name[f1]<<endl;
		for(int f2=0;f2<index[name[f1]].size();f2++)
		{
			cout<<index[name[f1]][f2]<<" ";
		}
		printf("\b");
		cout<<endl;
	}
	return 0;
}