SPOILER/CHEAT: Quick C++ solution

Nicholas Leippe nick at byu.edu
Fri Mar 10 16:16:54 MST 2006


#include <fstream>
#include <iostream>
#include <map>
#include <set>

using namespace std;

string<char> dictionary("/usr/share/dict/words");

int main(int argc, char** argv) {

	set<string> dict;
	map<string, int> count;
	ifstream d;
	d.open(dictionary.c_str());
	string word;
	while (d >> word) {
		dict.insert(word);
	}

	ifstream w(argv[1]);
	while (w >> word) {
		if (dict.find(word) != dict.end()) {
			count[word]++;
		}
	}

	for (map<string, int>::iterator i = count.begin();
	     i != count.end();
	     i++)
	{
		cout << (*i).first << ' ' << (*i).second << endl;
	}
	return 0;
};



-- 
Respectfully,

Nicholas Leippe
Sales Team Automation, LLC
1335 West 1650 North, Suite C
Springville, UT  84663 +1 801.853.4090
http://www.salesteamautomation.com



More information about the PLUG mailing list