Jumble Letter

Prashant started to attend programming lessons. On the first lesson, his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:

1.deletes all the vowels,

2.inserts a character "." before each consonant,

3.replaces all uppercase consonants with corresponding lowercase ones.

Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.

Help Prashant cope with this easy task.

Example:

Input:  s = "odn"
Output: .d.n

Approach

C++

#include <bits/stdc++.h>
using namespace std;

string jumbleLetter(string s)
{
    string res = "";
    for (int i = 0i < s.size(); i++)
    {
        if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] + 32;
    }

    for (int i = 0i < s.size(); i++)
    {
        if (s[i] == 'a' || s[i] == 'y' ||
            s[i] == 'e' || s[i] == 'o' ||
            s[i] == 'i' || s[i] == 'u')
        {
            continue;
        }
        else
        {
            res += '.';
            res += s[i];
        }
    }
    return res;
}
int main()
{
    string s = "odn";

    cout << jumbleLetter(s<< "\n";

    return 0;
}


No comments:

Post a Comment