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++: // index
#include <iostream>
#include <string>
// #include <algorithm>
#include <set>
#include <map>
using namespace std;

int main(){
  map< string, set<int> > index;
  string word;
  int page;

  while (cin >> word >> page){
    index[word].insert( page );
  }
  map< string, set<int> >::iterator it1 = index.begin();
  set<int>::iterator it2;
  while( it1 != index.end() ){
    cout << (*it1).first << endl;
    it2 = index[(*it1).first].begin();
    while( it2 != index[(*it1).first].end() ){
      cout << *it2;
      it2++;
    }
    cout << endl;
    it1++;
  }
  return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string a;
	map<string, vector<int>> d;
	while (cin >> a) {
		string b,h="";
		int c, sum = 0;
		a += " ";
		for (int i = 0; i < a. length(); i++) {
			if (a[i] == ' ') {
				if (sum == 0)
					b = h;
				else
					c = atoi(h.c_str());
				sum++;
				h = "";
			}
			else
				h += a[i];
		}
		d[b].push_back(c);
	}
	map<string, vector<int>>::iterator t = d.begin();
	while (t != d.end()) {
		string k = (*t).first;
		sort(d[k].begin(), d[k].end());
		cout << k;
		for (int i = 0; i != d[k].size(); i++) {
			cout << " " << d[k][i];
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<utility>
#include<queue>
using namespace std;
typedef pair<string,int> book;
int main(){
  string word,com="";
  int page;
  priority_queue<book,vector<book>,greater<book> > index;
  while(cin >> word){
    cin >> page;
    index.push(book(word,page));
  }
  while(!index.empty()){
    com = index.top().first;
    cout << com << endl << index.top().second;
    index.pop();
    while(index.top().first == com){
      cout << " " << index.top().second;
      index.pop();
      if(index.empty()) break;
    }
    cout << endl;
  }
}

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 (int 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 (int i = 0; i < words.size() - 1; i++) {
		for (int 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 (int i = 0; i < words.size(); i++) {
		for (int j = 0; j < pages[i].size()-1; j++) {
			for (int 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 (int i = 0; i < words.size(); i++) {
		cout << words[i] << endl;
		for (int m = 0; m < pages[i].size(); m++) {
			cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}

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

int main()
{
	int temp;
	int k,page;
	int i,flag=0;
	int j,count=0;
	string word;
	string index[1000];
	int num[1000][100];
	int appe[1000][2];
	memset(num,0,sizeof(num));
	memset(appe,0,sizeof(appe));
	for(i=0;i<1000;i++)
	{
		index[i]="";
	}
	while(cin>>word>>page)
	{
		for(j=0;j<flag;j++)
		{
			if(word.compare(index[j])!=0)
			{
				count++;
			}
			else
			{
				for(k=0;k<100;k++)
				{
					if(num[j][k]==0)
					{
						num[j][k]=page;
						break;
					}
				}
			}
		}

		if(count==flag)
		{
			index[flag]=word;
			num[flag][0]=page;
			appe[flag][0]=flag;
			appe[flag][1]=word.at(0)-'a';
		}
		count=0;
		flag++;
	}

	for(i=0;i<flag;i++)
	{
		for(j=0;j<flag-1-i;j++)
		{
			if(appe[j][1]>appe[j+1][1])
			{
				temp=appe[j][1];
				appe[j][1]=appe[j+1][1];
				appe[j+1][1]=temp;

				temp=appe[j][0];
				appe[j][0]=appe[j+1][0];
				appe[j+1][0]=temp;
			}
		}
	}

	for(i=0;i<flag;i++)
	{
		j=0;
		cout<<index[appe[i][0]]<<endl;		

		while(num[appe[i][0]][j]!=0)
		{
			cout<<num[appe[i][0]][j]<<" ";
			j++;
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;pair<string,int> a[100];int main(){int t=0,g,i;while(cin>>a[t].first>>a[t].second)t++;sort(a,a+t);string f,b=a[0].first;cout<<b<<endl<<a[0].second;for(i=1;i<t;i++){bool n=0;f=a[i].first,g=a[i].second;if(f==b)n=1;if(n)cout<<" "<<g;else cout<<endl<<f<<endl<<g;b=f;}cout<<endl;return 0;}

C++: #include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	map<string,vector<int> > m;
	map<string,vector<int> >::iterator it;
	vector<int>::iterator itv;
	string s;int a;
	while(cin>>s){
		cin>>a;
		m[s].push_back(a);
	}
	for(it=m.begin();it!=m.end();it++){
		cout<<it->first<<endl;
		sort(it->second.begin(),it->second.end());
		for(itv=it->second.begin();itv!=it->second.end() - 1;itv++)cout << *itv << ' ';
		cout << *itv << endl;
	}
}

C++: #include<iostream>
#include<map>
#include<set>
using namespace std;main(){int n;string s;map<string,set<int> >z;map<string,set<int> >::iterator q;set<int>::iterator x;while(cin>>s>>n)z[s].insert(n);for(q=z.begin();q!=z.end();cout<<endl){cout<<(s=q++->first)<<endl;for(x=z[s].begin(),n=0;x!=z[s].end();cout<<*x++)if(n++)cout<<" ";}}

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

using namespace std;

map<string, vector<int> > ans;

int main()
{
  string s;
  int n;
  while(cin >> s >> n)
  {
    ans[s].push_back(n);
  }

  for(map<string, vector<int> >:: iterator i = ans.begin(); i != ans.end(); i++)
  {
    cout << (*i).first << endl;

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
int main()
{
	map< string, vector<int> > m;
	int n, i;
	string s;
	while (cin >> s)
	{
		if (cin.eof()) break;
		cin >> n;
		m[s].push_back(n);
	}
	map< string, vector<int> >::iterator it = m.begin();
	while (it != m.end())
	{
		cout << (*it).first << endl;
		sort((*it).second.begin(), (*it).second.end());
		for (i = 0; i < (*it).second.size(); i++)
		{
			cout << (*it).second[i];
			if (i < (*it).second.size()-1)
				cout << " ";
			else
				cout << endl;
		}
		it++;
	}
}