Advertisement
Spocoman

The Most Powerful Word

Sep 22nd, 2023 (edited)
974
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 <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string word, vowels = "aeiouyAEIOUY", strongWord = "";
  8.     getline(cin, word);
  9.  
  10.     double strongSum = 0;
  11.  
  12.     while (word != "End of words") {
  13.         double wordSum = 0;
  14.  
  15.         for (int i = 0; i < word.length(); i++) {
  16.             wordSum += word[i];
  17.         }
  18.  
  19.         if (vowels.find(word[0]) != -1){
  20.             wordSum *= word.length();
  21.         }
  22.         else {
  23.             wordSum /= word.length();
  24.         }
  25.  
  26.         if (wordSum > strongSum) {
  27.             strongWord = word;
  28.             strongSum = wordSum;
  29.         }
  30.         getline(cin, word);
  31.     }
  32.  
  33.     cout << "The most powerful word is " << strongWord << " - " << (int)strongSum << endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement