Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	index := make(map[string]string)
	keys := []string{}
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		if index[l[0]] == "" {
			keys = append(keys, l[0])
		}
		index[l[0]] += l[1] + " "
	}
	sort.Strings(keys)
	for _, k := range keys {
		fmt.Println(k)
		p := strings.Split(strings.TrimRight(index[k], " "), " ")
		pages := []int{}
		for _, v := range p {
			i, _ := strconv.Atoi(v)
			pages = append(pages, i)
		}
		sort.Ints(pages)
		for i, v := range pages {
			if i > 0 {
				fmt.Printf(" ")
			}
			fmt.Printf("%d", v)
		}
		fmt.Println()
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i, f, n) for (int i = f; i < n; ++i)
#define rep(i, n) reep(i, 0, n)

typedef vector<int> vi;

int main()
{
    map<string, vi> table;
    char str[32];
    int p;
    while (scanf("%s %d", str, &p) != EOF)
    {
        string s(str);
        if (table.count(s))
            table[s].push_back(p);
        else
            table[s] = vi(1, p);
    }
    for (map<string, vi>::iterator itr = table.begin(); itr != table.end(); itr++)
    {
        sort(itr->second.begin(), itr->second.end());
        puts(itr->first.c_str());
        for (int i = 0; i < itr->second.size(); i++)
            printf("%s%d", i ? " " : "", itr->second[i]);
        puts("");
    }
    return 0;
}

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

int main() {
	vector<string> words;
	vector<vector<int>> pages;
	string word; int page;
	for (int k = 0; k < 7; k++) {
		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] << ':';
		for (int m = 0; m < pages[i].size(); m++) {
			cout << pages[i][m]<<' ';
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	string str = "";
	map <string, set<int> > Index;

	while (getline (cin, str ) ){

		string word = "";
		int page = 0;

		stringstream ss(str);
		ss >> word >> page;

		Index[word].insert (page );

	} // end loop

	map <string, set<int> >::iterator it = Index.begin();

	for (; it != Index.end(); ++it){

		string w = (*it).first;
		cout << w << endl;
	
		set<int>::iterator its = Index[w].begin();
		int n = Index[w].size();

		for (int i = 0; its != Index[w].end(); ++its, ++i){
			cout << (*its);
			if (i != n - 1){
				cout << ' ';
			} // end if
		} // end for

		cout << endl;	

	} // end for

	return 0;
}

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

static const int MAX_WORD_LEN = 30;
static const int MAX_PAGE_NUM = 1000;
static const int MAX_BOOK_NUM = 100;

static const int VOID_PAGE    = -1;

class BookIndex {
public:
  BookIndex() {}
  ~BookIndex() {}
  // ????????????????????°????????????
  void SetWord(string word_, int page_) {
    word_page.insert(M::value_type(word_, page_));
  }
  // ??¨??????????????????????????°?????????
  void PrintWords() {
    for (MIT it = word_page.begin(); it != word_page.end();) {
      cout << it->first << endl;
      int count = word_page.count(it->first);
      set<int> st;
      for (int i = 0; i < count; i++) {
        st.insert(it++->second);
      }
      set<int>::iterator st_it = st.begin();
      cout << *st_it++;
      for (; st_it != st.end();st_it++) {
        cout << " " << *st_it;
      }
      cout << endl;
    }
  }
private:
  typedef multimap<string, int> M;
  typedef M::iterator           MIT;
  M word_page;
};

int main() {
  BookIndex book;
  char input[MAX_WORD_LEN] = {};

  // ??\????????°
  string word;
  int    page;
  while (cin >> word, word != "0") {
    // ??\????????????????????§??????
    {
      char *ctx = NULL;
      cin >> input;
      page = atoi(input);
    }
    book.SetWord(word, page);
  }
  book.PrintWords();
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#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()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string temp;
    map<string,vi>mp;
    
    while(cin>>temp){
        int n; cin>>n;
        mp[temp].push_back(n);
        sort(all(mp[temp]));
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        cout<<itr->first<<" ";
        rep(i,mp[itr->first].size()){if(i)cout<<" ";cout<<mp[itr->first][i];}
        cout<<endl;
    }
}

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

map<string,vector<int>> p;

int main()
{
    string str;
    int t;
    while (cin >> str >> t) p[str].push_back(t);
    for (auto it = p.begin(); it != p.end(); it++) {
        sort(it->second.begin(), it->second.end());
        cout << it->first  << endl << it->second[0];
        for (int j = 1; j < it->second.size(); j++)
            cout << " " << it->second[j];
        cout << endl;
    }

    return 0;
}

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

using namespace std;
typedef pair<string, int> p;

void solve()
{
	vector<p> data;
	set<string> word;
	string str;
	while(cin >> str)
	{
		int num;
		cin >> num;
		p object(str, num);
		data.push_back(object);
		word.insert(str);
	}
	sort(data.begin(), data.end());
	set<string>::iterator it = word.begin();
	int pos = 0;
	while(it != word.end())
	{
		cout << *it << endl;
		bool flag = false;
		while(pos < data.size() && *it == data[pos].first)
		{
			if(flag)
			{
				cout << " ";
			}
			cout << data[pos].second;
			++pos;
			flag = true;
		}
		cout << endl;
		++it;
	}
}

int main()
{
	solve();
	return(0);
}