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>
#include<iostream>
using namespace std;

struct BK{string st;int p;};
int main(){
string str;
int N,iii=0;
BK B[101],T;
while(cin>>str>>N){
B[iii].st=str;B[iii].p=N;
iii++;
}
for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st<B[j-1].st){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st==B[j-1].st&&B[j].p<B[j-1].p){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
{if(i==0)cout<<B[0].st<<endl<<B[0].p;
else if(i>0&&B[i].st==B[i-1].st){cout<<" "<<B[i].p;}
else cout<<endl<<B[i].st<<endl<<B[i].p;
}
return 0;
}

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

typedef pair<string, int> P;

P words[110];

int main() {
  int i=0;

  string name; int page;
  while(cin >> name >> page) {
    words[i].first = name;
    words[i].second = page;

    i++;
    // cout << name << page << endl;
  }

  int n = i;

  
  for (int j=0; j<n-1; j++) {
    for (int k=0; k<n-1-j; k++) {
      if (words[k].first > words[k+1].first ||
	  (words[k].first == words[k+1].first &&
	   words[k].second > words[k+1].second)) {
	P temp = words[k];
	words[k] = words[k+1];
	words[k+1] = temp;
      }
    }
  }


  /*
    for (int j=0; j<n; j++) {
    cout << words[j].first << " " << words[j].second << endl;
    }
  */
  
  
  bool cont = false;
  for (int j=0; j<n; j++) {
    if (words[j].first == words[j+1].first) {
      if (!cont) {
	cout << words[j].first << endl;
	cont = true;
      } 
	cout << words[j].second << " ";
    } else {
      if (cont) {
	cout << words[j].second << endl;
	cont = false;
      } else {
	cout << words[j].first << endl << words[j].second << endl;
      }
    }
  }
  
}

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;
		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<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

#define PSI pair<string,int>

vector<PSI> book;

int main(void){
	int x;
	char tmp[1024];
	while(scanf("%s%d",tmp,&x)!=EOF){
		string a;
		a = tmp;
		book.push_back(PSI(a,x));
	}
	
	sort(book.begin(),book.end());
	
	for(int i = 0; i < book.size(); i++){
		vector<int> ans;
		puts(book[i].first.c_str());
		ans.push_back(book[i].second);
		while(i+1<book.size() && book[i+1].first==book[i].first){
			i++;
			ans.push_back(book[i].second);	
		}
		sort(ans.begin(),ans.end());
		for(int j = 0; j < ans.size(); j++){
			if(j != 0)printf(" ");
			printf("%d",ans[j]);
		}puts("");
		
	}
	return 0;
}

C++: #include<iostream>
#include<functional>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef pair<string,int> P;
int main(){
	string s,temp;
	int x;
	set<int> que;
	multimap<string,int> box;
	while(cin>>s>>x)
		box.insert(P(s,x));
	box.insert(P("zzzzzzz",0));
	multimap<string,int>::iterator ite;
	for(ite=box.begin();ite->second!=0;){
		temp=ite->first;
		que.insert(ite->second);
		ite++;
		while(ite->first==temp){
			que.insert(ite->second);
			ite++;
		}
		cout<<temp<<endl;
		set<int>::iterator se=que.begin();
		cout<<*se;
		se++;
		while(se!=que.end()){
			cout<<' '<<*se;
			se++;
		}
		cout<<endl;
		que.clear();
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st;
	map<string, vector<int>>mp;
	while (getline(cin,st)) {
		string name = st.substr(0, st.find(' '));
		int page = stoi(st.substr(st.find(' ') + 1));
		mp[name].push_back(page);
	}
	for (auto m : mp) {
		cout << m.first << endl;
		sort(m.second.begin(), m.second.end());
		for (int i = 0; i < m.second.size(); ++i) {
			cout << m.second[i];
			if (i == m.second.size() - 1)cout << endl;
			else cout << " ";

		}
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	map < string, vector <int> > index;
	string word;
	int page;
	while ( cin >> word >> page )
	{
		index[word].push_back( page );
	}

	for( map < string, vector <int> >::iterator it = index.begin(); it != index.end(); it++ )
	{
		cout << (*it).first << endl;
		vector <int>& pages = (*it).second;
		sort( pages.begin(), pages.end() );
		for ( vector <int>::iterator it_p = pages.begin(); it_p != pages.end(); it_p++ )
		{
			cout << *it_p;
			if ( it_p+1 != pages.end() )
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}

C++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1001
#define _MAX 100
#define HO 6
int main(void)
{
	char str[MAX];
	string word[_MAX];
	int pa[_MAX], rank[_MAX], cou, a;
	for (cou = 0; scanf_s("%s %d", str, MAX, &pa[cou]) != EOF;++cou) {
		string wo(str);
		word[cou] = wo;
		rank[cou] = cou;
	}
	for (int i = 0; i < cou; ++i) {
		for (int j = cou - 1; j > i; --j) {
			if (word[rank[j]] <= word[rank[j - 1]]) {
				if (word[rank[j]] == word[rank[j - 1]]) {
					if (pa[rank[j]] < pa[rank[j - 1]]) {
						a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
					}
				}
				else {
					a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a;
				}
			}
		}
	}
	for (int i = 0; i < cou; ++i) {
		if(i == 0 || word[rank[i - 1]] != word[rank[i]]) 
		cout << word[rank[i]] << "\n";
		if (i != 0 && word[rank[i - 1]] == word[rank[i]])
			printf(" ");
		printf("%d", pa[rank[i]]);
		if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]])
			printf("\n");
	}
	printf("\n");
}

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

struct dic{
	string s;
	int page[1001];
};

int comp(const void *a, const void *b){
if(((dic*)a)->s > ((dic*)b)->s) return 1;
else return -1;
}

int main(){
	int i,j,p,tail=0;
	string str;
	dic d[100];
	memset(d, 0, sizeof(d));
	while((cin >> str) != NULL){
		for(i=0;i<tail;i++){
			if(str == d[i].s){
				cin >> p;
				d[i].page[p]=1;
				break;
			}
		}
		if(i == tail){
			d[tail].s = str;
			cin >> p;
			d[tail].page[p]=1;
			tail++;
		}
	}

	qsort(&d,tail,sizeof(dic),comp);

	for(i=0;i<tail;i++){
		cout << d[i].s << endl;
		for(j=0;j<1001;j++) if(d[i].page[j] == 1) cout << j << " ";
		cout << endl;
	}
	return 0;
}