Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06.TheMostPowerfulWord
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string word = Console.ReadLine();
  10.  
  11.             bool hasVowel = false;
  12.             double totalValue = 0;
  13.             double mostPowerfullValue = 0;
  14.             string mostPowerfullWord = "";
  15.  
  16.             while (word != "End of words")
  17.             {
  18.                 double value = 0;
  19.                 int wordLength = word.Length;
  20.  
  21.                 for (int i = 0; i < wordLength; i++)
  22.                 {
  23.                     value += word[i];
  24.                     char symbol = word[i];
  25.                     if (i == 0)
  26.                     {
  27.                         symbol = char.ToLower(symbol);
  28.                         if (symbol == 'a' || symbol == 'e' || symbol == 'i' || symbol == 'o' || symbol == 'u' || symbol == 'y')
  29.                         {
  30.                             hasVowel = true;
  31.                         }
  32.                     }
  33.                 }
  34.                 if (hasVowel == true)
  35.                 {
  36.                     totalValue = value * wordLength;
  37.                 }
  38.                 else
  39.                 {
  40.                     totalValue = Math.Floor(value / wordLength);
  41.                 }
  42.                 if (mostPowerfullValue < totalValue)
  43.                 {
  44.                     mostPowerfullWord = word;
  45.                     mostPowerfullValue = totalValue;
  46.                 }
  47.                 word = Console.ReadLine();
  48.                 hasVowel = false;
  49.             }
  50.             Console.WriteLine($"The most powerful word is {mostPowerfullWord} - {mostPowerfullValue}");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement