| Код | #include <iostream> #include <vector> #include <fstream>
const int MAX = 6;
double find_percent(const std::string& word) { static const char vowel [MAX] = {'a','e','i','o','u','y'}; int count = 0; for (int i = 0; i < word.size(); i++) { for (int j = 0; j < MAX; ++j) if(word[i] == vowel[j]) ++count; } return (count * 100 / word.size()); }
int main(int argc, char* argv[]) { std::fstream file("WORDS.TXT", std::ios::in); std::vector<std::string> word_arr; if (!file) return -1; while (!file.eof()) { std::string word; std::getline(file, word, '\n'); if (word.size() != 0) word_arr.push_back(word); } std::string ex_word; double cur_percent = 0; for (int i = 0; i < word_arr.size(); ++i) { double buf = find_percent(word_arr[i]); if (buf > cur_percent) { ex_word = word_arr[i]; cur_percent = buf; } } std::cout << ex_word; getchar(); return 0; }
|
|