Replace by Next Vowel
The program must accept a string S and an alphabet CH as the input. The program must replace all the occurrences of the alphabet CH by the next occurring vowel in the string S. Then the program must print the modified string as the output.
Note: If there is no vowel after the alphabet CH then CH must be printed as it is.
Note: If there is no vowel after the alphabet CH then CH must be printed as it is.
Boundary Condition(s):
1 <= Length of the string <= 1000
1 <= Length of the string <= 1000
Input Format:
The first line contains the string S and an alphabet CH separated by a space.
The first line contains the string S and an alphabet CH separated by a space.
Output Format:
The first line contains the modified string.
The first line contains the modified string.
Example Input/Output 1:
Input:
teleportation t
Input:
teleportation t
Output:
eeleporaaiion
eeleporaaiion
Example Input/Output 2:
Input:
accuracy c
Input:
accuracy c
Output:
auuuracy
auuuracy
Solution:-
#include<stdio.h>
#include <stdlib.h>
int vowel(char a)
{
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
{
return 1;
}
return 0;
}
int main()
{
char s[1000],a;
scanf("%s %c",s,&a);
int len=strlen(s);
int flag=0;
for(int i=0;i<strlen(s);i++)
{
if(s[i]!=a)
{
printf("%c",s[i]);
}
else
{
int t=i+1;
flag=0;
while(t<len)
{
if(vowel(s[t])==1){
printf("%c",s[t]);
flag=1;
break;
}
t++;
}
if(flag==0)
{
printf("%c",a);
}
}
}
}
Comments
Post a Comment