Mercurial > hg > toys
view main.c++ @ 7:feead6f50850
Modified it to read from filename, added Makefile per problem description
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Sat, 01 Jan 2011 03:29:19 -0600 |
parents | cad6633bc1fc |
children |
line wrap: on
line source
#include "bk-tree.c++" #include <fstream> #include <sstream> #include <algorithm> void string_to_upper(std::string& str) { std::transform( str.begin(), str.end(), str.begin(), &toupper); } int main(int argc, char** argv) { using namespace std; bk_tree tree; { ifstream ifs("tree"); load_tree(tree,ifs); } string filename = argv[1]; ifstream ifs(filename.c_str()); size_t total_distance = 0; string word; while( ifs >> word) { string_to_upper(word); size_t m = word.size(); for(size_t i = 0; i < word.size(); i++) { if( query_tree(tree,word,i) ) { m = i; break; } } total_distance += m; } cout << total_distance << endl; }