Declare a pointer at the beginning of the input character array and a pointer at the beginning of the resulting character array , initializing them with i = j = 0. For each character in the string that is not a vowel, copy to and move the pointer one position forward. If the character is a vowel, add it twice to the end of the string , and then increment by two positions.
Algorithm implementation
Declare the input character array and the resulting array .
char s[1001], t[2001];Read the input string.
gets(s);Copy the character to and increment the index by . If is a vowel, add it twice to the array .
int j = 0;
for (int i = 0; i < strlen(s); i++)
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||
s[i] == 'u' || s[i] == 'y')
{
t[j++] = s[i];
t[j++] = s[i];
}
else
t[j++] = s[i];At the end of the resulting string, write a null byte to indicate its termination.
t[j] = 0;Print the answer.
puts(t);Algorithm implementation — C++
Read the input string.
getline(cin, s);Initialize an empty string , that will contain the result.
res = "";Iterate over the characters of the string .
If is a vowel, add two characters to .
If is a consonant, add one characters to .
for (i = 0; i < s.size(); i++)
{Add the character to .
res = res + s[i];If is a vowel, add it to once more.
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||
s[i] == 'u' || s[i] == 'y')
res = res + s[i];
}Print the answer.
cout << res;Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
String s = con.nextLine();
String res = "";
for(int i = 0; i < s.length(); i++)
if (s.charAt(i) == 'a' || s.charAt(i) == 'e' ||
s.charAt(i) == 'i' || s.charAt(i) == 'o' ||
s.charAt(i) == 'u' || s.charAt(i) == 'y' )
res = res + s.charAt(i) + s.charAt(i);
else
res = res + s.charAt(i);
System.out.println(res);
con.close();
}
}Python implementation
Read the input string.
s = input()Initialize an empty string , that will contain the result.
res = ""Iterate over the characters of the string .
If is a vowel, add two characters to .
If is a consonant, add one characters to .
for ch in s:Add the character to .
res += chIf is a vowel, add it to once more.
if ch in "aeiouy":
res += chPrint the answer.
print(res)