#include #include #include #include using namespace std; string convert(string s) { string result = ""; for (int i = 0; i < s.length(); i += 1) { char c = s[i]; if (islower(c)) result += c; else if (isupper(c)) result += (char)tolower(c); else if (isdigit(c)) result += c; } return result; } struct item { string word; int count; }; void swapif(item array[], int a, int b) { if (array[a].count > array[b].count) { const item t = array[a]; array[a] = array[b]; array[b] = t; } } int main() { ifstream in("/home/www/text/barrie/peterpan"); if (in.fail()) { cout << "Can't read home/www/text/barrie/peterpan\n"; exit(1); } const int max = 47800; item data[max]; int number = 0; for (int i = 0; i < max; i += 1) { data[i].word = ""; data[i].count = 0; } while (true) { string word; in >> word; if (in.fail()) break; word = convert(word); if (word == "") continue; bool matched = false; for (int i = 0; i < number; i += 1) if (data[i].word == word) { data[i].count += 1; matched = true; break; } if (! matched) { if (number >= max) { cout << "The arrays are not big enough\n"; exit(1); } data[number].word = word; data[number].count = 1; number += 1; } } in.close(); for (int last = number - 1; last > 0; last -= 1) for (int first = 0; first <= number - 2; first += 1) swapif(data, first, first + 1); for (int i = 0; i < number; i += 1) cout << data[i].word << " " << data[i].count << "\n"; }