
Deprecated: Function set_magic_quotes_runtime() is deprecated in /DISK2/WWW/lokiware.info/mff/wakka.php on line 35
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <cctype>

int main()
{
	std::map<std::string, std::vector<unsigned> > stat;
	std::map<std::string, std::vector<unsigned> >::iterator iStat, jStat;
	std::vector<unsigned> tmp;

	char c = 0;
	std::string word;
	unsigned lineNumber = 1;    // pocitadlo radek
	int i;

	while (c != EOF) {

		c = std::cin.get();

		if (c == '\n')
			lineNumber++;

		// NACITANI SLOVA

		word.clear();    // vyprazdneni stringu

		if (isalpha(c) || c == '_')
			while (isalpha(c) || isdigit(c) || c == '_') {
				word = word + c;
				c = std::cin.get();
			}
			
		if (word.empty())    // aby se nepridavala prazdna slova
			continue;

		// ZPRACOVANI SLOVA
			
		iStat = stat.find(word.c_str());    // najde slovo v mape

		if (iStat == stat.end()) {    // slovo v mape jeste neni
			tmp.push_back(lineNumber);    // prida radku vyskytu
			stat.insert(make_pair(word, tmp));    // prida slovo do mapy
			tmp.pop_back();
                }
		else if (iStat->second[iStat->second.size() - 1] != lineNumber)
			iStat->second.push_back(lineNumber);    // pridani vyskytu

		if (c == '\n')
			lineNumber++;
	}

	// VYPIS SLOV OD NEJVETSIHO POCTU VYSKYTU

	while (! stat.empty()) {
		jStat = stat.begin();
		iStat = stat.begin();

		while (iStat != stat.end()) {    // vybere slovo s nejvetsim poctem vyskytu
			if (jStat->second.size() < iStat->second.size())
				jStat = iStat;
			iStat++;
		}

		std::cout << jStat->first << ": ";    // vypise slovo
		for (i = 0; i < jStat->second.size(); i++)
			std::cout << jStat->second.at(i) << "  ";    // vypise vyskyt
		std::cout << std::endl;

		stat.erase(jStat);    // vymaze slovo z mapy
	}
}
