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

    return 0;
}

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

typedef map<string, set<int> > Dict;
Dict dict;
int main(){
  int p;
  string s;
  while(cin >> s >> p){
    dict[s].insert(p);
  }
  for(Dict::iterator it = dict.begin(); it != dict.end(); it++){
    cout << it->first << endl;
    int i = 0;
    for(set<int>::iterator it2 = (*it).second.begin(); it2 != (*it).second.end(); it2++, i++){
      if(i)cout << " ";
      cout << *it2;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
pair<string,int> p;
vector<pair<string,int> > v;
while(cin>>p.first>>p.second){
v.push_back(make_pair(p.first,p.second));
}
sort(v.begin(),v.end());

cout<<v[0].first<<endl;
cout<<v[0].second;
string bef=v[0].first;
for (int i = 1; i < v.size(); ++i) {
    if(bef!=v[i].first){
    	cout<<endl;
    	cout<<v[i].first<<endl;
    	cout<<v[i].second;
    	bef=v[i].first;
    }else{
    	cout<<" "<<v[i].second;
    }
}
cout<<endl;
}

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

int main(){
	string str;
	int page;
	map<string,vector<int>> dict;

	while(cin >> str >> page){
		dict[str].push_back(page);
	}

	for(map<string,vector<int>>::iterator it = dict.begin(); it != dict.end(); it++){
		sort(it->second.begin(), it->second.end());

		cout << it->first << endl;

		for(int i = 0; i < (int)it->second.size(); i++){
			cout << it->second[i];
			cout << ((i < (int)it->second.size()-1)?' ':'\n');
		}
	}
}

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

int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,!std::cin.eof()){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::sort((*m_it).second.begin(),(*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while(v_it!=(*m_it).second.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it!=(*m_it).second.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}
/*
Sample Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output for the Sample Input
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
*/

C++: #include<iostream>
#include<functional>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef pair<string,int> P;
int main(){
	string s,temp;
	int x;
	map<string,set<int> > box;
	while(cin>>s>>x)
		box[s].insert(x);
	map<string,set<int> >::iterator ite;
	set<int>::iterator t;
	for(ite=box.begin();ite!=box.end();ite++){
		cout<<ite->first<<endl;
		for(set<int>::iterator se=ite->second.begin();ite->second.end()!=se;se++){
			cout<<*se;
			se++;
			t=se--;
			cout<<(t!=ite->second.end()?' ':'\n');
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
class data{
public:
  string words;  
  int page;
  bool operator < (const data&s)const{
    if(words < s.words) return true;
    else if(words > s.words) return false;
    else{
      if(page < s.page) return true;
      else return false;
    }
  }
};
int main(){
  int i=0;
  data in[1000];
  while(cin >> in[i].words){
    cin >> in[i].page;
    i++;
  }
  
  sort(in,in+i);

  cout << in[0].words << endl << in[0].page;
  for(int j=1;j<i;j++){
    if(in[j-1].words != in[j].words){
      cout << endl;
      cout << in[j].words << endl << in[j].page;
    }
    else{
      cout << ' ' << in[j].page;
    }
  }
  cout << endl;
  return 0;
}

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