#include #include #include #include using namespace std; string trim(string s) { string r = ""; for (int i = 0; i < s.length(); i += 1) { char c = s[i]; if (isalpha(c)) r += (char)tolower(c); } return r; } int main() { ifstream ppin; ppin.open("/home/www/text/barrie/peterpan"); if (ppin.fail()) { cout << "Couldn't open the file\n"; exit(1); } string words[48000]; int counts[48000]; int num = 0; for (int i = 0; i < 48000; i += 1) counts[i] = 0; while (true) { string s; ppin >> s; if (ppin.fail()) break; s = trim(s); if (s == "") continue; int pos = 0; while (pos < num) { if (words[pos] == s) break; pos += 1; } if (words[pos] == "") { words[pos] = s; num += 1; } counts[pos] += 1; } ppin.close(); for (int last = num; last > 0; last -= 1) for (int second = 1; second < last; second += 1) if (counts[second-1] > counts[second]) { swap(counts[second-1], counts[second]); swap(words[second-1], words[second]); } for (int i = 0; i < num ; i += 1) cout << words[i] << ": " << counts[i] << "\n"; }