Zoho - Second round- Reversing the vowels
Given a string, reverse only the vowels present in it and print the resulting string.
Input: First line of the input file contains an integer T denoting the number of test cases. Then T test cases follow. Each test case has a single line containing a string.
Output: Corresponding to each test case, output the string with vowels reversed.
Example:
Input:
practice
Output:
prectica
C++ Program:
Input: First line of the input file contains an integer T denoting the number of test cases. Then T test cases follow. Each test case has a single line containing a string.
Output: Corresponding to each test case, output the string with vowels reversed.
Example:
Input:
practice
Output:
prectica
C++ Program:
#include<iostream> #include<conio.h> #include<string.h> using namespace std; int main() { string a,b; cin >> a; int len= a.length(); int count=0; for(int i=0;i<len;i++) { if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u') { b=b+a[i]; count+=1; } } for(int i=0;i<len;i++) { if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u') { count -=1; a[i]=b[count]; } } cout <<a; getch(); return 0; }Happy Coding
Comments
Post a Comment