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 <bits/stdc++.h>

int main(){
    std::map<std::string, std::vector<int> > ind;
    while (true){
        std::string s;
        int n;
        std::cin>>s>>n;
        if(std::cin.fail())break;
        ind[s].push_back(n);
    }
    for (auto &i : ind) {
        std::cout<< i.first<<std::endl;
        std::sort(i.second.begin(),i.second.end());
        for (size_t j = 0; j < i.second.size()-1; ++j) {
            std::cout<< i.second[j]<<" ";
        }
        std::cout<< i.second[i.second.size()-1]<<std::endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	string ans = "";
	int in;
	map <string ,vector <int> > mp;
	while(cin >> s >> in){
		mp[s].push_back(in);
	}
	for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
		cout << (*itr).first << endl;
		sort((*itr).second.begin(),(*itr).second.end());
		for(int i = 0; i < (*itr).second.size() ; i++)
			cout << (*itr).second[i] << (i == (*itr).second.size() - 1 ? "" : " ");
		cout << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

map<string, vector<int> > list;

int main(void){
	string S;
	int n;
	while(cin >> S >> n, n){
		list[S].push_back(n);
	}
	while(cin >> S){
		sort(list[S].begin(), list[S].end());
		rep(i, list[S].size()){
			if(i != 0)cout << " ";
			cout << list[S][i];
		}
		cout << endl;
	}
	

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	vector<pair<string, vector<int> > > v = vector<pair<string, vector<int> > >();
	string s;
	int n;
	while (cin >> s >> n)
	{
		int ok = true;
		for (int i = 0; i < v.size(); i++)
		{
			if (v[i].first == s)
			{
				ok = false;
				v[i].second.push_back(n);
			}
		}
		if (ok)
			v.push_back({ s,vector<int>{n} });
	}
	for (int i = 0; i < v.size(); i++)
		sort(v[i].second.begin(), v[i].second.end());
	for(int i = 0; i < v.size(); i++)
		for (int j = i + 1; j < v.size(); j++)
		{
			if (v[i].first > v[j].first)
			{
				pair<string, vector<int> > r = v[i];
				v[i] = v[j];
				v[j] = r;

			}
		}
	for (int i = 0; i < v.size(); i++)
	{
		cout << v[i].first << endl;
		for (int j = 0; j < v[i].second.size() - 1; j++)
		{
			cout << v[i].second[j] << " ";
		}
		cout << *(v[i].second.end()) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define INF 1<<20

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	cout << d[TO] << endl;
}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n+1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n+1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int main(){
	map<string, vector<int> > dic;
	string voc;
	int page;
	while (cin >> voc >> page) {
		dic[voc].push_back(page);
	}
	map<string, vector<int> >::iterator it = dic.begin();
	while(it!=dic.end()) {
		cout << (*it).first<<endl;
		sort((*it).second.begin(), (*it).second.end());
		for (int i = 0;i < (*it).second.size();i++) {
			if (i == (*it).second.size() - 1) {
				cout << (*it).second[i];
			}
			else cout << (*it).second[i] << " ";
		}
		cout << endl;
		it++;
	}
	
}

int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}

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

int main() {
	map<string, vector<int> > book;
	string title;
	int page;
	while(cin >> title >> page) {
		book[title].push_back(page);
	}
	for(map<string, vector<int> >::iterator itr = book.begin(); itr != book.end(); itr++) {
		printf("%s\n", (*itr).first.c_str());
		for(vector<int>::iterator sc = (*itr).second.begin(); sc != (*itr).second.end(); sc++) {
			printf("%d ", *sc);
		}
		printf("\n");
	}
	return 0;
}