Thursday, November 16, 2017

Replace String - Next Vowel & Consonant

A string S is passed as input. The program must replace the vowels with next occurring consonant and the consonants with next occurring vowel.

Input Format:
The first line will contain the value of the string S.

Boundary Conditions: 1 <= Length of S <= 100

Output Format:
The string value with the vowels and consonants replaced as per the given conditions.

Example Input/Output 1:
Input:
quiz
Output:
uvja
Explanation: z is the last letter. Hence starting from a, a is the next occuring vowel.

Solution:
def isvowel(c):
    if c=='a' or c=='e' or c=='i' or c=='o' or c=='u':
        return 1
    return 0
s=input()
for i in s:
    if isvowel(i):
        print(chr(ord(i)+1),end='')
    else:
        while not isvowel(i):
            i = chr(ord(i)+1)
        print(i,end='')
Share: