Advertisement
Guest User

vowel counting

a guest
Oct 24th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main(int argc, char **argv)
  7. {
  8.     setlocale( LC_ALL,"Russian" );
  9.    
  10.     multimap<size_t, string> words;
  11.    
  12.     cout << "Введите слова (ctrl+z для остановки): " << endl;
  13.     for(string word;;)
  14.     {
  15.         cin >> word;
  16.        
  17.         if (cin.eof())
  18.             break;
  19.  
  20.         size_t vowel_count = count_if(word.begin(), word.end(),
  21.             [](char c){ return string("aeiou").find_first_of(c) != string::npos; });
  22.  
  23.         words.insert(make_pair(vowel_count, word));
  24.     }
  25.  
  26.     if (words.size() != 0)
  27.     {
  28.         double percent = (100.0*words.rbegin()->first) / words.rbegin()->second.size();
  29.         cout << "word: " << words.rbegin()->second << endl;
  30.         cout << "percent: " << percent << endl;
  31.     }
  32.  
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement