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++: //============================================================================
// Name        : aoj0105.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

typedef struct{
	char word[31];
	int page;
}Quate;

int compare(const void *a,const void *b){
	Quate qa, qb;
	qa = *(Quate *)a;
	qb = *(Quate *)b;
	if(strcmp(qa.word,qb.word) != 0){
		return strcmp(qa.word,qb.word);
	}else{
		return qa.page - qb.page;
	}
}


int main() {
	char tmp[31] = "";
	Quate q[1000];
	int n = 0, i;
	while(scanf("%s%d%*c",q[n].word,&q[n].page) != EOF){
		n++;
	}
	qsort(q,n,sizeof(q[0]),compare);
	for(i = 0;i < n;i++){
		if(strcmp(tmp,q[i].word) == 0){
			printf(" %d",q[i].page);
		}else{
			if(strcmp(tmp,"") != 0){
				printf("\n");
			}
			printf("%s\n%d",q[i].word,q[i].page);
		}
		strcpy(tmp,q[i].word);
	}

	return 0;
}

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

typedef pair<string,int> P;

int main(){
  string str;
  int page,cnt=0;
  vector<P> v;

  while(cin >> str >> page){
    v.push_back(P(str,page));
    cnt++;
  }

  sort(v.begin(),v.end());
  for(int i = 0 ; i < cnt; i++){
    if(i==0){
      cout << v[i].first << endl;
      cout << v[i].second;
      continue;
    }

    if(v[i].first == v[i-1].first && v[i].second!=v[i-1].second){
      cout << ' ' << v[i].second;
      continue;
    }
   
    puts("");
    puts("");
    cout << v[i].first << endl;
    cout << v[i].second;
    }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<pair<string,int>> str(100000);
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int count = 0;
    int c_n = 0;
    while (cin >> str[count].first) {
        cin >> str[count].second;
        count++;
    }
    sort(str.begin(), str.begin() + count);
    cout << str[0].first << endl;
    cout << str[0].second;
    for (int i = 1; i < count; i++) {
        if (str[i].first != str[i-1].first) {
            cout << endl << str[i].first << endl;
            cout << str[i].second;           
        } else {
            cout << " " << str[i].second;
        }
    }
    cout << endl;
    return 0;
}

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

class WP {
public:
	std::string word;
	int page;
public:
	WP() {
		this->word = "";
		this->page = 0;
	}
	WP( std::string word, int page ) {
		this->word = word;
		this->page = page;
	}
	bool operator>=(const WP& rhs) {
		if (this->word.compare(rhs.word) > 0) return true;
		else if (this->word.compare(rhs.word) < 0) return false;
		else {
			return (this->page >= rhs.page);
		}
	}
	bool operator>(const WP& rhs) {
		if (this->word.compare(rhs.word) > 0) return true;
		else if (this->word.compare(rhs.word) < 0) return false;
		else {
			return (this->page > rhs.page);
		}
	}
	bool operator<=(const WP& rhs) {
		if (this->word.compare(rhs.word) < 0) return true;
		else if (this->word.compare(rhs.word) > 0) return false;
		else {
			return (this->page <= rhs.page);
		}
	}
	bool operator<(const WP& rhs) {
		if (this->word.compare(rhs.word) < 0) return true;
		else if (this->word.compare(rhs.word) > 0) return false;
		else {
			return (this->page < rhs.page);
		}
	}
	bool operator==(const WP& rhs) {
		if (this->word.compare(rhs.word) != 0) return false;
		else {
			return (this->page == rhs.page);
		}
	}
	bool operator!=(const WP& rhs) {
		if (this->word.compare(rhs.word) != 0) return true;
		else {
			return (this->page != rhs.page);
		}
	}
	~WP() {}
};

int main()
{
	WP words_list[100];
	std::string word;
	int page;
	int input_size = 0;
	while (std::cin >> word >> page) {
		words_list[input_size] = WP(word, page);
		input_size++;
	}
	
	std::sort(words_list, words_list + input_size);
	
	for (int i=0; i<input_size; i++) {
		std::cout << words_list[i].word << std::endl;
		std::cout << words_list[i].page;
		while (words_list[i].word == words_list[i+1].word) {
			i++;
			std::cout << " " << words_list[i].page;
		}
		std::cout << std::endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
map<string,priority_queue<int,vector<int>,greater<int> > > Map;
signed main(void){
	ios::sync_with_stdio(false);
	string s;
	int page;
	while(cin>>s>>page)
		Map[s].push(page);
	for(map<string,priority_queue<int,vector<int>,greater<int> > >::iterator it=Map.begin();it!=Map.end();++it){
		if(it!=Map.begin())	cout<<endl;
		cout<<it->first<<endl;
		while(!it->second.empty()){
			cout<<it->second.top()<<" ";
			it->second.pop();
		}
	}
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	map<string, vector<int>> mp;
	string s;
	int a;
	while (cin >> s >> a) {
		mp[s].emplace_back(a);
	}
	sort(mp[s].begin(), mp[s].end());
	for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
		cout << itr->first<< endl;
		sort(mp[itr->first].begin(), mp[itr->first].end());
		for (int i = 0; i < mp[itr->first].size(); i++) {
			cout << mp[itr->first][i];
			if (i != mp[itr->first].size() - 1)cout << " ";
			else cout << endl;
		}
	}
}

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,{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 <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	map<string, vector<int> > dict;
	
	string s;
	int p;
	while (cin >> s >> p) {
		dict[s].push_back(p);
	}
	
	map<string, vector<int> >::iterator it;
	for (it = dict.begin(); it != dict.end(); it++) {
		vector<int> v = (*it).second;
		int size = v.size();
		
		sort(v.begin(), v.end());
		
		cout << (*it).first << endl;
		for (int i = 0; i < size - 1; i++) {
			cout << v[i] << " ";
		}
		cout << v[size - 1] << endl;
	}
	
	return 0;
}