/* indexvec.cpp - Matt Mahoney, mmahoney@cs.fit.edu This program reads text from standard input and prints an alphabetically sorted list of words and the number of times each word occurs. A word is defined as a sequence of one or more letters and no other characters. For purposes of counting, differences in case are ignored. For instance, "Don't" is 2 words, "don" and "t". The output is in two columns with the count first. For instance, if input.txt is: Don, don't do that. Then the command: indexmap #include #include #include #include using namespace std; int main() { // Read the input, parsing into lowercase words. // Store the words in a vector, wordlist, in lower case format. char c; string word; vector wordlist; while (cin.get(c)) { if (isalpha(c)) word += char(tolower(c)); else if (word != "") { wordlist.push_back(word); word = ""; } } // Sort wordlist, bringing identical words together sort(wordlist.begin(), wordlist.end()); // Print the unique words in wordlist along with their repeat counts. int count=1; // How many times the current word has been seen. for (int i=0; i