Question:
Given string/sentence need to be reversed and the vowels need to be replaced with numbers from 1-9.In the reversed string replaced numbers should appear in descending from left to right. If there are more than 9 vowels, numbering should restart from 1.
If the input string is Language, output string should be 4g32gn1L
Function description
Complete the function strRevRep in the editor below. The function must print the string in reverse order after replacing vowels with numbers.
functionName has the following parameter:
intStr : string
Constraints
Maximum length of string is 50. If the length is greater than 50 Invalid Input should be displayed
In the output string the numbers need to appear in descending order from left to right.
a,e,I,o,u and A,E,I,O,U both should be treated same.
Sample Case 0:
Sample Input From Custom testing
Language
Sample Output
4g32gn1L
Explanation
String got reversed and vowels in the string a,u,a,e got replaced with 1,2,3 and 4. In the final output string numbers are appearing in descending order from left to right.
Input:
Language
Output:
4g32gn1L
Solution:
Python :
#https://codewindow.in
#join our telegram channel @codewindow
def strRevRep(inpStr,k):
x="aeiou"
c=0
ans=[]
for i in inpStr:
if i in x:
c+=1
ans+=str(c)
else:
ans+=i
print(''.join(ans[::-1]))
if _name_ =='_main_':
inpStr = input()
strRevRep(inpStr,0)
JAVA :
//https://codewindow.in
//join our telegram channel @codewindow
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class CodeWindow
{
public static void main (String[] args) throws Exception
{
// your code goes here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str1 = br.readLine();
String str2 = "";
int c=1;
for(int i=0;i<str1.length();i++){
if(str1.charAt(i) == 'a' || str1.charAt(i) == 'e' || str1.charAt(i) == 'i' || str1.charAt(i) == 'o' || str1.charAt(i) == 'u' || str1.charAt(i) == 'A' || str1.charAt(i) == 'E' || str1.charAt(i) == 'I' || str1.charAt(i) == 'O' || str1.charAt(i) == 'U') {
str2 += c++;
} else {
str2 += str1.charAt(i);
}
}
for(int i=0;i<str2.length();i++)
System.out.print(str2.charAt(str2.length()-i-1));
}
}
C++ :
//https://codewindow.in
//join our telegram channel @codewindow
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
// your code goes here
string str1;
cin >> str1;
string str2 = "";
int c=1;
for(int i=0;i<str1.length();i++){
if(str1.at(i) == 'a' || str1.at(i) == 'e' || str1.at(i) == 'i' || str1.at(i) == 'o' || str1.at(i) == 'u' || str1.at(i) == 'A' || str1.at(i) == 'E' || str1.at(i) == 'I' || str1.at(i) == 'O' || str1.at(i) == 'U') {
str2 += c+++48;
} else {
str2 += str1.at(i);
}
}
for(int i=0;i<str2.length();i++) {
cout << str2.at(str2.length()-i-1);
}
return 0;
}
Also Checkout