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<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string temp;
    map<string,vi>mp;
    
    while(cin>>temp){
        int n; cin>>n;
        mp[temp].push_back(n);
        sort(all(mp[temp]));
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        cout<<itr->first<<" ";
        rep(i,mp[itr->first].size()){if(i)cout<<" ";cout<<mp[itr->first][i];}
        cout<<endl;
    }
}

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 <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	string str; int n;
	multimap<string,int> ans;
	while(cin>>str>>n)
		ans.insert(pair<string,int>(str,n));
	multimap<string,int>::iterator p;
	for(p=ans.begin();p!=ans.end(); )
	{
		string tmp= p->first;
		cout << tmp << endl;
		int cnt=0;
		vector<int> v;
		do
		{
			v.push_back(p->second); p++;
		}while(p!=ans.upper_bound(tmp));
		sort(v.begin(),v.end());
		for(int i=0;i<v.size();i++)
		{
			if(i) cout << ' ' ;
			cout << v[i] ;
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::string buf;
	int p;
	std::map<std::string, std::vector<int> > map;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	std::cin.rdbuf(ifs.rdbuf());
#endif

	while(std::cin >> buf >> p){
		map[buf].push_back(p);
	}

	for(std::map<std::string, std::vector<int> >::const_iterator it = map.begin(); it != map.end(); it++){
		std::vector<int> pages = it->second;
		std::sort(pages.begin(), pages.end());

		std::cout << it->first << std::endl;
		std::cout << pages[0];
		for(int i = 1; i < pages.size(); i++){
			std::cout << " " << pages[i];
		}
		std::cout << std::endl;
	}


#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <functional>

using namespace std;

void solve()
{
	map<string, priority_queue<int, vector<int>, greater<int>> > Map;
	string str;
	int page;
	while(cin >> str >> page)
	{
		Map[str].push(page);
	}
	for(map<string, priority_queue<int, vector<int>, greater<int>> >::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
	{
		cout << Ite->first << endl;
		bool FirstFlag = true;
		while(!Ite->second.empty())
		{
			if(FirstFlag)
			{
				cout << Ite->second.top();
				FirstFlag = false;
			}
			else
			{
				cout << " " << Ite->second.top();
			}
			Ite->second.pop();
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

C++: #include<iostream>
//#include<pair>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

class data{
public:
	vector<int> num;
	string s;
};

int main(){
	int n;
	string str;
	vector<data> vec;
	while(cin>>str){
		cin>>n;
		data dt;
		dt.num.push_back(n);
		dt.s=str;
		int cnt=0;
		for(int i=0;i<vec.size();i++){
			if(str==vec[i].s){
				vec[i].num.push_back(n);
				cnt++;
			}
		}
		if(cnt==0)vec.push_back(dt);
	}
	//rep(i,vec.size())cout<<vec[i].s<<" ";
	//cout<<endl;
	//for(int i=0;i<vec.size();i++)cout<<vec[i].s<<" ";
	//cout<<endl;
	for(int i=0;i<vec.size();i++){
		//cout<<i<<endl;
		for(int j=vec.size()-1;j>=1;j--){
			//cout<<j<<" ";
			if(vec[j-1].s>vec[j].s){
				data alt=vec[j];
				vec[j]=vec[j-1];
				vec[j-1]=alt;
			}
			//rep(i,vec.size())cout<<vec[i].s<<" ";
			//cout<<endl;
		}
		//cout<<endl;
	}
	for(int i=0;i<vec.size();i++){
		int volume=vec[i].num.size();
		sort(vec[i].num.begin(),vec[i].num.end());
	}
	for(int i=0;i<vec.size();i++){
		cout<<vec[i].s<<endl;
		cout<<vec[i].num[0];
		for(int j=1;j<vec[i].num.size();j++){
			cout<<" "<<vec[i].num[j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num,page[1000][100]={},nu[1000]={};
    memset(nu,0,sizeof(nu));
    string str[1000],s;
    while(cin>>s>>num){
        for(int i=0;i<=sen;i++){
            if(str[i]==s){
                nu[i]++;
                page[i][nu[i]]=num;
                num=-1;
            }
        }
        if(num!=-1){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    int kawa;
    for(int i=0;i<sen;i++){
        num=0;
        for(int j=0;j<sen;j++){
            if(str[j]!="zzzzzzzzzzzzzzz"&&str[num]>str[j])num=j;
        }
        cout<<str[num]<<endl;
        str[num]="zzzzzzzzzzzzzzzzzzzzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num]-1;k>0;k--){
                if(page[num][k]<page[num][k-1]){
                    kawa=page[num][k-1];
                    page[num][k-1]=page[num][k];
                    page[num][k]=kawa;
                }
            }
        }
        cout<<page[num][0];
        for(int j=1;j<=nu[num];j++)cout<<" "<<page[num][j];
        cout<<endl;
    }
}