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++: import java.util.*;
import java.io.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String, ArrayList<Integer>> map = new TreeMap<String, ArrayList<Integer>>();
		ArrayList<Integer> page ;

		while (sc.hasNext() ) {
			String key = sc.next();
			int pageIn = sc.nextInt();
			if ( !map.containsKey(key) ) {
				map.put(key, new ArrayList<Integer>() );
			}
			map.get(key).add(pageIn);
		}
		
		
		Iterator it = map.keySet().iterator();
		while (it.hasNext()) {
			String key = (String) it.next();
			ArrayList <Integer> list = map.get(key);
			Collections.sort(list);
			System.out.println(key);
			for(int i = 0; i < list.size(); i++){
				if(i == 0){
					System.out.print(list.get(i));
				}else{
					System.out.print(" " + list.get(i));
				}
			}
			System.out.println();
			
                 }
		
	}

}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>

using namespace std;


string w,p;

void f_output(string p){
    int output[101]={0};
    
    stringstream stream;
    stream<<p;
    int x;
    int count=0;
    while(stream>>x){
        output[count]=x;
        count++;
    }
    
    sort(output, output+count);
    cout<<output[0];
    for(int i=1; i<count; i++)cout<<" "<<output[i];
    cout<<endl;
}


int main(){
    map<string, string> book;
    
    while(cin>>w>>p){
        if(book.find(w)==book.end()){
            book[w]=p;
        }else{
            book[w]=book[w]+" "+p;
        }
    }
    
    for (map<string, string>::iterator itr = book.begin(); itr != book.end(); itr++)
	{
		// キーを出力
		cout << itr->first << endl;
		// 値を出力
		f_output(itr->second);
	}
    
}

/*
int main()
{
    
    string w="123 222";
    stringstream stream;
    stream<<w;
    int x;
    while(stream>>x){
        cout<<x<<endl;
    }
    

}
*/

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string w;
  int p;
  map<string, vi> m;
  while (cin >> w >> p) m[w].pb(p);
  for (auto x : m) {
    cout << x.fi << endl;
    sort(all(x.se));
    if (x.se.size()) cout << x.se[0];
    loop(i, 1, x.se.size()) cout << ' ' << x.se[i];
    cout << endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string name[111], a;
	int na, kazu[111], date[111][111], b;
	for (int i = 1; i <= 101; i++) {
		kazu[i] = 0;
	}
	na = 0;
	while (cin >> a >> b) {
		for (int i = 1; i <= na; i++) {
			if (name[i] == a) {
				kazu[i] = kazu[i] + 1;
				date[i][kazu[i]] = b;
				goto a;
			}
		}
		na = na + 1;
		name[na] = a;
		kazu[na] = 1;
		date[na][kazu[na]] = b;
	a:;
	}
	string aa;
	int bb,min,mi;
	for (int i = 1; i <= na; i++) {
		aa = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz";
		for (int z = 1; z <= na; z++) {
			if (aa >= name[z]) {
				aa = name[z];
				bb = z;
			}
		}
		cout << aa << endl;
		name[bb] = "zzzzzzzzzzzzzzzzzzzzzzzz";
		for (int z = 1; z <= kazu[bb]; z++) {
			min = 9999;
			for (int m = 1; m <= kazu[bb]; m++) {
				if (date[bb][m] <= min) {
					min = date[bb][m];
					mi = m;
				}
			}
			cout << min << " ";
			date[bb][mi] = 9999;
		}
		cout << endl;
	}
}

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

#define SWAP(A, B) {int tmp = (B); (B) = (A); (A) = (tmp);}

int main() {
	char word[100][31];
	int pagenum[100];
	int sortnum[100];
	int count;

	for (int i = 0; i < 100; i++)
		sortnum[i] = i;

	for (count = 0; cin >> word[count] >> pagenum[count] != NULL; count++);

	for (int i = 0; i < count; i++) {
		for (int j = 0; j < count - i - 1; j++) {
			if (strcmp(word[sortnum[j]], word[sortnum[j+1]]) > 0)
				SWAP(sortnum[j], sortnum[j+1]);
		}
	}

	for (int i = 0; i < count; i++) {
		if (strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0) {
			int j, flag = 0;
			for (j = i
				; j < count - 1 && strcmp(word[sortnum[j]], word[sortnum[j+1]]) == 0
				; j++) 
			{
				if (pagenum[sortnum[j]] > pagenum[sortnum[j+1]]) {
					SWAP(sortnum[j], sortnum[j+1]);
					flag = 1;
				}
			}
			if (flag)
				i--;
			else
				i = j;
		}
	}

	for (int i = 0; i < count; i++) {
		cout << word[sortnum[i]] << endl;
		if (strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0) {
			for (; i < count && strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0; i++) {
				cout << pagenum[sortnum[i]] << ' ';
			}
		}
		cout << pagenum[sortnum[i]] << endl;
	}
			system("pause");
	return 0;
}

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

int main() {
	vector<string> words;
	vector<vector<int>> pages;
	string word; int page;
	while(cin>>word>>page) {
		bool is_there = false; int word_place;
		for (unsigned i = 0; i < words.size(); i++) {
			if (word == words[i]) {
				is_there = true;
				word_place = i;
			}
		}
		if (is_there) {
			pages[word_place].push_back(page);
		}
		else {
			words.push_back(word);
			vector<int>* x = new vector<int>;
			pages.push_back(*x);
			pages[pages.size() - 1].push_back(page);
		}
	}
	for (unsigned i = 0; i < words.size() - 1; i++) {
		for (unsigned j = 0; j < words.size() - 1; j++) {
			if (words[j] > words[j + 1]) {
				string tmp_w=words[j];
				words[j] = words[j + 1];
				words[j + 1] = tmp_w;
				vector<int> tmp_p=pages[j];
				pages[j] = pages[j + 1];
				pages[j + 1] = tmp_p;
			}
		}
	}
	for (unsigned i = 0; i < words.size(); i++) {
		for (unsigned j = 0; j < pages[i].size()-1; j++) {
			for (unsigned c = 0; c < pages[i].size()-1; c++) {
				if (pages[i][c] > pages[i][c + 1]) {
					int tmp=pages[i][c];
					pages[i][c] = pages[i][c + 1];
					pages[i][c + 1] = tmp;
					}
			}
		}
	}
	for (unsigned i = 0; i < words.size(); i++) {
		cout << words[i] << endl;
		for (unsigned m = 0; m < pages[i].size(); m++) {
			cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}