/*****************************************************************************
 * This program illustrates the use of 'map'. the 'main' function reads strings
 * from the keyboard and uses them as keys to for a map. Each key maps to the
 * number of times the key appeared in the input. Because the element for each 
 * key is value initialized, the count starts at zero.
 *****************************************************************************/

#include<iostream>
#include<string>
#include<map>
using std::cout; using std::cin; using std::endl;
using std::string; using std::map;
	

int main()
{
	
	cout<<"Enter some text, <ENTER><CTRL-D> to stop: " ;
	string current;
	map<string, int> count;
	while(cin>>current)
		count[current]++;
	/* If 'current' is new, this creates a new element with the value '0',
	 * then increments it to '1'. if 'current has been seen already, this
	 * increments its count.
	 */
	for(map<string, int>::const_iterator it=count.begin();
			it!=count.end(); it++)
		/* The elements of a map are pairs, with the key in 'first'
		 * and the value in 'second'. The arrow is a handy way to get
		 * from an iterator to a member of the object it indicates.
		 * Here, it->first replaces (*it).first, for example.
		 */
		cout<<it->first<<" "<<it->second<<endl;
	
	
	return 0;
}

