Toggle Consonants Adjacent to Vowels
Coding Problem Keys
Toggle Consonants Adjacent to Vowels
Problem Statement
The program must accept a string S containing only alphabets both in lower and upper case. The program must toggle the case of the consonants (non-vowels) adjacent to the vowels.
Boundary Condition(s)
2 <= Length of the string S <= 100
Input Format
The first line contains the string value S.
Output Format
The first line contains the toggle consonants between vowels.
Example Input/Output 1
Input
adJaeCent
Output
aDjaeceNt
Example Input/Output 2
Input
mAtRIMonY
Output
MATrImoNY
Note: Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: Python 3 Language
# Published By PKJCODERSs=input().strip() vow="AEIOUaeiou" for i in range(len(s)): if s[i] not in vow and ((i>0 and s[i-1] in vow) or (i+1<len(s) and s[i+1] in vow)): print(s[i].swapcase(),end="") else: print(s[i],end="")
Alter
# Published By PKJCODERSdef display(y): if y.islower():print(y.upper(),end='') else:print(y.lower(),end='') s=""+input().strip()+"" n='aeiouAEIOU' for i in range(len(s)): if s[i] not in n and ((i>0 and s[i-1] in n) or (i+1<len(s) and s[i+1] in n)): display(s[i]) else: print(s[i],end='')
Programming Language: C Language
//Published By PKJCODERS#include<stdio.h> #include <stdlib.h> int main(){ int i,j,k,n; char s[100]; scanf("%s",s); char x,l,m; n=strlen(s); for(i=0;i<n;i++){ x=tolower(s[i]); l=tolower(s[i-1]); m=tolower(s[i+1]); if(x=='a'||x=='e'||x=='i'||x=='o'||x=='u') printf("%c",s[i]); else if((x!='a'&&x!='e'&&x!='i'&&x!='o'&&x!='u')&&(l=='a'||l=='e'||l=='i'||l=='o'||l=='u')||(m=='a'||m=='e'||m=='i'||m=='o'||m=='u')) if(isupper(s[i])) printf("%c",tolower(s[i])); else printf("%c",toupper(s[i])); else printf("%c",s[i]); } }
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments