/** * 对一段英文的词频统计 * @Author xxingup@gmail.com * date 2010/06/17 */ #include <iostream> #include <string> using namespace std; /** * 单词对象 */ struct Word { Word() : Str(""), Count(0) {} string Str; int Count; /** * 交换单词(用于排序) * @param word 交换的单词对象 */ void exchange(Word &word) { string tStr = word.Str; int tCount = word.Count; word.Str = Str; word.Count = Count; Str = tStr; Count = tCount; } }; /** * 统计词频 * @param words 单词数组 * @param newWord 单词内容 * @param size 单词总数 */ void CalcCount(Word * words, string &newWord, int size) { int i = 0; for(; i < size; i++) { if(words[i].Str == newWord) { words[i].Count++; return; } else if(wo