int main() { Trie dict; std::ifstream dictfile("twl06.txt"); std::string s; while (dictfile >> s) { dict.InsertWord(s); } dictfile.close(); std::vector<std::string> words; std::string input; while (std::cin >> input) { std::istringstream buffer(input); std::vector<std::string> temp {std::istream_iterator<std::string>(buffer), std::istream_iterator<std::string>()}; for (auto& w : temp) { words.push_back(std::move(w)); } } auto totalDistance = 0; for (auto& word : words) { //auto dist = distance(word, &dict); totalDistance += distance(word, &dict); //std::cout << word << ": " << dist << std::endl; } std::cout << totalDistance << std::endl; return 0; }
/* Dict::initialize: returns true if the map is ready to be searched, false otherwise. */ bool Dict::initialize() { ifstream dictfile(dictfileName.c_str(), ifstream::in); if (dictfile.good()) { loadDict(); } else { cout << "Dictionary file not present. Creating new file. This may take some time..." << endl; createDict(); } if (USE_BLACKLIST) { try { blacklistfile.open(blacklistfileName.c_str(), ifstream::in); // cout << "Loading Blacklist..." << endl; if (blacklistfile.good()) loadBlacklist(); } catch (ifstream::failure e) { cout << "Warning: Blacklist file not present!" << endl; } } return true; }