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 <algorithm>
#include <set>
#include <vector>
#include <map>

using namespace std;

int main(){
  map<string, vector<int> > m;
  vector<string> keys;

  char s[32];
  int n;
  while(scanf(" %s %d",s,&n)!=EOF){
    string str(s);
    if(m.find(str) != m.end()){
      m[s].push_back(n);
    }else {
      keys.push_back(str);
      m.insert(pair<string,vector<int> >(s, vector<int>(1, n)));
    }
  }

  sort(keys.begin(), keys.end());
  vector<string>::iterator it;
  for(it=keys.begin();it!=keys.end();it++){
    printf("%s\n", (*it).c_str());

    vector<int> v = m[(*it)];

    sort(v.begin(), v.end());

    vector<int>::iterator it2;
    it2=v.begin();
    while(1){
      printf("%d", (*it2));
      it2++;
      if(it2!=v.end()) printf(" ");
      else{ printf("\n");break;}
    }
  }
  return 0;
}

C++: //Name: Book Index
//Level: 2
//Category: やるだけ
//Note:

/**
 * mapを使って語句とページ番号を管理すると、語句は勝手に昇順に並ぶ。
 * ページ番号は出力時にソートする。
 *
 * オーダーは O(N|S| log N)。
 * ただしNは語句の個数、|S|は語句の最大長。
 */
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

bool solve() {
    string word;
    int page;
    map<string,vector<int>> dict;
    while(cin >> word >> page) {
        dict[word].push_back(page);
    }
    for(auto &e : dict) {
        cout << e.first << endl;
        sort(begin(e.second), end(e.second));
        for(int i = 0; i < (int)e.second.size(); ++i) {
            if(i > 0) cout << ' ';
            cout << e.second[i];
        }
        cout << endl;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}

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

pair<string, int> S[100000];
int cnt;

int main() {
	while (cin >> S[cnt].first >> S[cnt].second) {
		cnt++;
	}
	sort(S, S + cnt);
	for (int i = 0; i < cnt; i++) {
		if (i >= 1) {
			if (S[i].first == S[i - 1].first) {
				cout << ' ' << S[i].second;
			}
			else {
				cout << endl << S[i].first << endl << S[i].second;
			}
		}
		else {
			cout << S[i].first << endl << S[i].second;
		}
	}
	cout << endl;
	return 0;
}

C++: #include<map>
#include<set>
#include<string>
#include<iostream>

using namespace std;

int main()
{
	string key;
	int page;
	map< string,set<int> > dic;

	while(cin>>key>>page)	dic[key].insert(page);

	map< string,set<int> >::iterator it_dic;
	for(it_dic=dic.begin();it_dic!=dic.end();it_dic++){
		cout<<it_dic->first<<endl;
		set<int>::iterator it;
		for(it=it_dic->second.begin();it!=it_dic->second.end();it++){
			if(it!=it_dic->second.begin())	cout<<" ";
			cout<<*it;
		}
		cout<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	map < string, vector<int> > index;

	string sbuf;
	int ibuf;

	while (cin>>sbuf>>ibuf)
	{
		index[sbuf].push_back(ibuf);
	}

	for (auto &elem : index)
	{
		sort(elem.second.begin(), elem.second.end());
		cout << elem.first << endl;
		for (auto &vecElem : elem.second)
		{
			cout << vecElem << " ";
		}
		cout << endl;
	}

	return 0;
}

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

using namespace std;

struct info{
	string word;
	int p;
	int page[1000];
};

void intsort(int a[1000], int p)
{
	int t;
	for(int i = p; i >= 0; i--){
		for(int j = 1; j <= i; j++){
			if(a[j] < a[j-1]){
				t = a[j];
				a[j] = a[j-1];
				a[j-1] = t;
			}
		}
	}
	return ;
}

void strsort(info a[101], int p)
{
	info t;
	for(int i = p; i >= 0; i--){
		for(int j = 1; j <= i; j++){
			if(a[j-1].word > a[j].word){
				t = a[j];
				a[j] = a[j-1];
				a[j-1] = t;
			}
		}
	}
	return ;
}

int main()
{
	string str;
	int s, t = 0;
	info index[101];
	bool f;

	while(cin >> str >> s){
		if(t > 0){
			f = true;
			for(int i = 0; i < t; i++){
				if(str == index[i].word){
					index[i].page[index[i].p] = s;
					index[i].p += 1;
					f = false;
					break;
				}
			}
			if(f){
				index[t].word = str;
				index[t].page[0] = s;
				index[t].p = 1;
				t++;
			}
		} else {
			index[t].word = str;
			index[t].p = 1;
			index[t].page[0] = s;
			t++;
		}
	}
	
	for(int i = 0; i < t; i++){
		intsort(index[i].page, index[i].p-1);
	}
	strsort(index, t-1);
	
	for(int i = 0; i < t; i++){
		cout << index[i].word << endl;
		cout << index[i].page[0];
		for(int j = 1; j < index[i].p; j++){
			cout << " " << index[i].page[j];
		}
		cout << endl;
	}
	
	return 0;
}

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

using namespace std;
/** Problem0105 : Book Index **/
int main()
{
	map<string, vector<int> >index;
	string s; int p;
	
	while (cin >> s >> p) {
		index[s].push_back(p);
	}
	
	map<string, vector<int> >::iterator it = index.begin();
	for (;it != index.end(); it++) {
		cout << it->first << endl;
		
		sort(index[it->first].begin(), index[it->first].end());
		
		vector<int>::iterator it2 = index[it->first].begin();
		cout << *it2;
		for (++it2 ;it2 != index[it->first].end(); it2++) {
			cout << " " << *it2;
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;int main(){string s;int n;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();q++){s=q->first;cout<<s<<endl;for(x=z[s].begin();x!=z[s].end();x++){if(x!=z[s].begin())cout<<" ";cout<<*x;}cout<<endl;}return 0;}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct w{string s;long p;
w(string s_,long p_):s(s_),p(p_){}
};
class cm{
public:
bool operator()(const w& a,const w& b){
if(a.s==b.s)return a.p<b.p;
else return a.s<b.s;
}
};
int main(){
vector<w> ww;
long p,i,j,n,f;
string s;
while(cin>>s>>p){
ww.push_back(w(s,p));
}
sort(ww.begin(),ww.end(),cm());
n=ww.size();
for(i=0;i<n;i++){
cout<<ww[i].s<<endl;f=0;
for(;i<n;i++){
if(f>0)cout<<" ";cout<<ww[i].p;f=1;
if(i<n-1&&ww[i].s!=ww[i+1].s){cout<<endl;break;}
}
}
cout<<endl;
return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

using namespace std;



int main()
{
	map<string, vector<int> > index;
	string s;
	int n;
	
	while (cin >> s >> n)
	{
		index[s].push_back(n);
		sort(index[s].begin(), index[s].end());
	}
	
	map<string, vector<int> >::const_iterator it;
	vector<int>::const_iterator it2;
	for (it=index.begin(); it!=index.end(); it++)
	{
		cout << (*it).first << endl;
		for (it2=(*it).second.begin(); it2!=(*it).second.end()-1; it2++)
		{
			cout << (*it2) << " ";
		}
		cout << (*it2) << endl;
	}
	
	return 0;
}