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

using namespace std;

typedef map<string, vector<int> > M;

int main() {
  M pairs;
  string word;
  while (cin >> word) {
    int page;
    cin >> page;
    pairs[word].push_back(page);
  }
  for (M::iterator i = pairs.begin(); i != pairs.end(); ++i) {
    cout << i->first << endl;
    sort(i->second.begin(), i->second.end());
    for (vector<int>::iterator j = i->second.begin();
         j != i->second.end()-1; ++j)
      cout << *j << ' ';
    cout << i->second.back() << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	vector< pair<string, int> > data;
	string str;
	int a;
	while (cin >> str >> a) {
		data.push_back(pair<string, int>(str, a));
	}
	sort(data.begin(), data.end());

	pair<string, int> preData;
	for (pair<string, int> e : data) {
		if (preData.first == e.first) {
			cout << " " << e.second;
		}
		else {
			cout << endl << e.first << endl << e.second;
		}
		preData = e;
	}
	cout << endl;
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    map<string,int>mp;
    map<string,vi>hoge;
    vector<string>v;
    string temp; int cnt;
    while(cin>>temp>>cnt){
        if(mp[temp]==0){v.push_back(temp);hoge[temp].push_back(cnt);mp[temp]++;}
        else{
            hoge[temp].push_back(cnt);
        }
    }
    sort(all(v));
    rep(i,v.size()){
        cout<<v[i]<<endl;
        sort(all(hoge[v[i]]));
        rep(j,hoge[v[i]].size())if(j)cout<<" "<<hoge[v[i]][j]; else cout<<hoge[v[i]][j];
        cout<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int sen=0,num,page[1000][100]={},nu[1000]={};
    memset(nu,0,sizeof(nu));
    string str[1000],s;
    while(cin>>s>>num){
        for(int i=0;i<sen;i++){
            if(str[i]==s){
                nu[i]++;
                page[i][nu[i]]=num;
                num=-1;
            }
        }
        if(num!=-1){
            str[sen]=s;
            page[sen][0]=num;
            sen++;
        }
    }
    int kawa;
    for(int i=0;i<sen;i++){
        num=0;
        for(int j=0;j<sen;j++)if(str[num]>str[j])num=j;
        cout<<str[num]<<endl;
        str[num]="zzzzzzzzzzzzz";
        for(int j=0;j<nu[num];j++){
            for(int k=nu[num];k>0;k--){
                if(page[num][k]<page[num][k-1]){
                    kawa=page[num][k-1];
                    page[num][k-1]=page[num][k];
                    page[num][k]=kawa;
                }
            }
        }
        cout<<page[num][0];
        for(int j=1;j<=nu[num];j++)cout<<" "<<page[num][j];
        cout<<endl;
    }
}

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

int main(){
  multimap<string,int> Index;
  string s;
  int val;
  vector<int> thisisit;
  while(cin  >> s >> val){
    Index.insert(multimap<string,int>::value_type(s,val));
  }
 


  multimap<string,int>::iterator it = Index.begin();
  while(it != Index.end()){
    cout << it->first << endl;
    thisisit.clear();
    int fin = Index.count(it->first);
    for(int i=0;i<fin;i++,it++){
      thisisit.push_back(it->second);
    }
    partial_sort(thisisit.begin(),thisisit.begin()+fin,thisisit.end());
    for(int i=0;i<fin;i++){
      cout << thisisit[i];
      if(i != fin-1)cout << " "; 
    } 
   cout << endl;

  }





  return 0;
}

C++: #include <iostream>
#include <map>
#include <set>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    map<string, set<int> > m;
    string t;
    int n;
    while (cin >> t >> n) m[t].insert(n);
    for(map<string, set<int> >::iterator i = m.begin(); i != m.end(); ++i) {
        cout << i->first << endl;
        ostringstream os;
        for(set<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
            os << " " << *j;
        cout << os.str().substr(1) << endl;
    }
    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;
		}
	}
	


}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

vector< PS > vs;
string s;
ll n;

int main(){
	while (cin >> s >> n){
		vs.push_back(PS(s, n));
	}
	sort(ALL(vs));
	s = "";
	REP(i, vs.size()){
		if (s != vs[i].first){
			cout << vs[i].first << endl;
			s = vs[i].first;
		}
		if (i == vs.size() - 1){
			cout << vs[i].second << endl;
			continue;
		}
		if (vs[i + 1].first != s){
			cout << vs[i].second << endl;
		}
		else{
			cout << vs[i].second << " ";
		}
	}
}