//(c)Terminator
#include <iostream>
#include <cctype>
#include <cstring>
#include <string>
#include <map>
using namespace std;

struct scmp {
	bool operator () (const string& a, const string& b) const {
		return (strcmp(a.c_str(), b.c_str()) < 0);
	}
};

typedef map<string, int, scmp> words;


int maxrepeat_word(const char* s, string& d){
	words::iterator pw;
	const char* p;
	string  w;
	words  ws;
	int n = 0;

	for(d = ""; *s; s = p) {

		while(*s && ! isalpha(*s))
			++s;
		if(! *s)
			break;
		for(p = s; isalpha(*p); )
			++p;

		w.assign(s, p);
		if((pw = ws.find(w)) != ws.end()){
			if(++(pw->second) > n){
				d = w;
				n = pw->second;
			}
		} else
			ws.insert(make_pair(w, 1));
	}

	ws.clear();
	return n;
}



int main(void){
	char s[] = "dog, fox, [dog], fox, wolf-dog, cat, dog";

	string d;
	int    n = maxrepeat_word(s, d);
	cout << "word:  " << d << endl;
	cout << "count: " << n << endl;
	return 0;
}