Epic Systems Interview Question
Software Engineer / Developers/*
barring the first 3 vowels in a string , replace all vowels a e i o u, with '_' ,. At the same time not more than 4 vowels from the last shud be changed.
*/
#include<iostream>
#include<string>
using namespace std;
string replace_vowel(string s)
{
if (s.length()<=3) return s;
else
{
int count_front=0,count_rear=0;
int index=-1;
for (int i=0;i<3;i++)
{
index=s.find_first_of("aeiou",index+1);
if (index!=string::npos)
count_front++;
}
if (count_front<3) return s;
else
{
int rear_index=s.length();
while (count_rear<4)
{
rear_index=s.find_last_of("aeiou",rear_index-1);
if (rear_index!=string::npos && rear_index>index)
s[rear_index]='_';
count_rear++;
}
return s;
}
}
}
int main ()
{
cout << "Enter the string\n";
string str;
getline(cin,str);
cout<<replace_vowel(str)<<endl;
}
package switchvow;
public class vow {
public static void main(String[] args) {
String str = "an apple a morning keeps me yawning";
StringBuilder sb = new StringBuilder();
char[] s=str.toCharArray();
for(char c:s){
System.out.print(c);}
System.out.println("");
int count=0;
for(char c:s){
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
count++;
}
}
int len=0;
if(count<=7){
len=count-3;
}
else{
len=4;
}
for(int i=s.length-1;i>0;i--){
if(len>0){
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){
sb.append("^"+s[i]);
s[i]=(char) (s[i]-'a'+'A');
len--;
} else {
sb.append(s[i]);
}
}else{
sb.append(s[i]);
}
}
sb.append(s[0]);
System.out.println(sb.reverse().toString());
for(char c:s){
System.out.print(c);}
}
}
is the question incomplete ?
- anon July 02, 2010