#include #include #include using namespace std; #include "ctimer.h" #include "tvector.h" #include "sortall.h" int countAll(tvector& list) // post: list of all words/counts printed, list // is sorted { sort(list.begin(), list.end()); string last = list[0]; int count = 1; int uniqCount = 1; for(int k=1; k < list.size(); k++) { if (list[k] != last) { last = list[k]; count = 1; uniqCount++; } else { count++; } } return uniqCount; } int main(int argc, char * argv[]) { ifstream input; string filename,s; int count; if (argc > 1) { filename = argv[1]; } else { cout << "filename "; cin >> filename; } input.open(filename.c_str()); CTimer timer; tvector words; count = 0; while (input >> s) { words.push_back(s); count++; } timer.Start(); int ucount = countAll(words); timer.Stop(); cout << timer.ElapsedTime() << " " << count << " " << ucount << endl; return 0; }