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

#define out cout 
#define in cin
#define el endl

#define rep(i, N) for (int i = 0; i < N; i++)
#define ol(N) cout << N << endl

int main()
{
	int a, c = 0;
	string s;
	map<string, vector<int>> m;

	while (in >> s >> a){
		m[s].push_back(a);
	}
	for (auto chie : m) {
		cout << chie.first << '\n';
		sort(chie.second.begin(), chie.second.end());
		rep(i, chie.second.size() - 1) {
			cout << chie.second[i] << " ";
		}
		cout << chie.second[chie.second.size() - 1] << '\n';
	}

	return (0);
}

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

class package
{
public:
	string word;
	int page;
	package(string _word, int _page)
	{
		word = _word;
		page = _page;
	}

};
bool compare(const package & left, const package & right)
{
	if(left.word < right.word)
	{
		return true;
	}
	if(left.word == right.word && left.page <= right.page)
	{
		return true;
	}
	return false;
}
int main()
{

	vector<package> book;
	
	while(1)
	{
		string str = "";
		int page;
		cin >> str;
		if(str == "")
		{
			break;
		}
		cin >> page;
		package index(str, page);
		book.push_back(index);
	}

	sort(book.begin(), book.end(), compare);

	string lastWord = book[0].word;
	cout << book[0].word << endl;
	cout << book[0].page;

	for(int i = 1; i < book.size(); i++)
	{
		if(lastWord == book[i].word)
		{
			cout << " " << book[i].page;
			
		}
		else
		{
			cout << endl;
			cout << book[i].word << endl;
			cout << book[i].page;
			lastWord = book[i].word;
		}
	}
	cout << endl;
	


}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

struct book_info{
	char phrase[32];
	int pageNum[101];
};

int main(){
	
	int i,page;
	char inputStr[32];
	bool flag;
	struct book_info index[101]={'\0',0};
	
	memset(inputStr,'\0',sizeof(inputStr));
	
	
	//入力
	for(i=0;i<101;i++){
		
		if(scanf("%s %d",inputStr,&page)==EOF){
			break;
		}
		
		flag=true;
		
		//入力済みの単語かどうかを調べる
		int j;
		for(j=0;j<i;j++){
			//入力済みなら
			if(strcmp(index[j].phrase,inputStr)==0){
				//ページ番号の記憶
				for(int k=0;k<100;k++){
					if(index[j].pageNum[k]==0){
						index[j].pageNum[k]=page;
						break;
					}
				}
				flag=false;
				break;
			}
		}
		
		//入力されてないなら
		if(flag){
				strcpy(index[j+1].phrase,inputStr);
				index[j+1].pageNum[0]=page;
		}
		
		memset(inputStr,'\0',sizeof(inputStr));
	}
	
	
	//単語昇順バブルソート
	for(int j=0;j<i;j++){
		for(int k=i-1;k>j;k--){
			if(strcmp(index[k-1].phrase,index[k].phrase)>0){
				   struct book_info temp;
				   temp=index[k];
				   index[k]=index[k-1];
				   index[k-1]=temp;				
			}
		}
	}
	
	//単語昇順かつページ番号昇順バブルソート
	for(int g=0;g<i;g++){
		for(int j=0;j<100;j++){
			for(int k=100-1;k>j;k--){
				if((index[g].pageNum[k-1]>index[g].pageNum[k]) && 
				    index[g].pageNum[k-1]!=0 &&
				    index[g].pageNum[k]!=0){		
						int temp;
						temp=index[g].pageNum[k];
						index[g].pageNum[k]=index[g].pageNum[k-1];
						index[g].pageNum[k-1]=temp;				
				}
			}
		}
	}
	
	for(int j=0;j<i;j++){
		if(index[j].phrase[0]!='\0'){
			cout<<index[j].phrase<<endl;
		}
		for(int k=0;k<100 && index[j].pageNum[k]!=0;k++){
			if(index[j].pageNum[k+1]!=0){
				cout<<index[j].pageNum[k]<<" ";
			}else{
				cout<<index[j].pageNum[k]<<endl;
			}
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<map>
#include<stack>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;
 
int main() {
  int index;
  char word[40] = {};
  char words_list[110][40] = {};
  map < string, int > dic;
  int page_cnt[110] = {};
  int page[110][40] = {};
  int i = 1, k;
  while(scanf("%s %d", word, &index) != EOF) {
    if(dic[word] == 0) {
      dic[word] = i;
      strcpy(words_list[i], word);
      //cout << word << ' ' << index << endl;
      i++;
    }
    int k = dic[word];
    page[k][page_cnt[k]++] = index;
    // page[k].push_back(index);
    // page[dic[word]][page[dic[word]].size()] = index;
    //cout << word << index << endl;
  }

  for(int j = 1; j < i - 1; j++) {
    for(int k = i - 1; k > j; k--) {
      if(strcmp(words_list[j], words_list[k]) > 0) {
        swap(words_list[j], words_list[k]);
	swap(dic[words_list[j]], dic[words_list[k]]);
	swap(page[j], page[k]);
	swap(page_cnt[j], page_cnt[k]);
      }
    }
  }
  
  for(int j = 1; j < i ; j++) {
    sort(page[j], page[j] + page_cnt[j]);
    cout << words_list[j] << endl;
    for(k = 0; k < page_cnt[j] - 1; k++) {
      cout << page[j][k] << ' ';
    }
    cout << page[j][k] << 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();
	for (;it == dic.end();it++) {
		cout << (*it).first<<endl;
		sort((*it).second.begin(), (*it).second.end());
		for (int i = 0;i < (*it).second.size();i++)
		cout << (*it).second[i]<<" ";
	}
	
}

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;
}