settingsAccountsettings
Menusettings

Q: Illuminati - C# Task

+7 votes

The illuminati are an ancient, very secret society that very secretly rules the world. They’ve managed to keep their existence secret by using a very secretive way of communication. Their secret is that they incorporate their secret messages into popular (non-secret) movies.

Your task is to extract the meaning of some movie lines. The messages are actually codes that can be extracted by summing the secret values of every vowel in the message. The values of the vowels are as follows: A = 65, E = 69, I = 73, O = 79, U = 85. The values apply for both upper and lowercase letters. For example, ‘I am Batman!’ has a total of 4 vowels: three times ‘A’ and one time ‘I and their sum is: 3 * 65 + 1 * 73 = 268.

Input

  • The input data should be read from the console.
  • The only input line holds the message that has to be deciphered.

The input data will always be valid and in the format described. There is no need to check it explicitly.

Output

  • The output data should be printed on the console.
  • On the first output line you must print the number of vowels in the message.
  • On the second output line you must print the sum of all the vowels in the message.

Constraints

  • The length of the message will be between 1 and 800 000 characters.
  • Allowed working time for your program: 0.1 seconds.
  • Allowed memory: 16 MB.

Examples

illuminati c# task

asked in C# category by user Jolie Ann
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

Here's my solution, Jolie:

using System;

class Illuminati
{
    static void Main()
    {
        string data = Console.ReadLine();
        char[] dataAr = data.ToCharArray();

        decimal sum = 0;
        decimal vows = 0;

        for (int i = 0; i < dataAr.Length; i++)
        {
            if (dataAr[i] == 'A' || dataAr[i] == 'a')
            {
                sum += 65;
                vows++;
            }
            if (dataAr[i] == 'E' || dataAr[i] == 'e')
            {
                sum += 69;
                vows++;
            }
            if (dataAr[i] == 'I' || dataAr[i] == 'i')
            {
                sum += 73;
                vows++;
            }
            if (dataAr[i] == 'O' || dataAr[i] == 'o')
            {
                sum += 79;
                vows++;
            }
            if (dataAr[i] == 'U' || dataAr[i] == 'u')
            {
                sum += 85;
                vows++;
            }
        }
        Console.WriteLine(vows);
        Console.WriteLine(sum);
    }
}

 

answered by user matthew44
selected by user golearnweb
...