Epic Systems Interview Question
System Administratorsprivate static void ReplaceVovelsByIntegers(string input)
{
List<char> vovels = new List<char>(new char[] { 'A', 'a', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U' });
StringBuilder output = new StringBuilder();
int nVovels = 0;
foreach (char c in input)
{
if (vovels.Contains(c))
{
output.Append(c);
nVovels++;
if (nVovels > 3)
{
output.Append('^');
}
}
}
}
int main()
{
string s = "greateribblizing";
string temp ="";
string rem = s;
int count = 0;
for(int i = 0; i < rem.length(); i++)
{
if(rem[i] == 'A' ||rem[i] == 'a'||rem[i] == 'E'||rem[i] == 'e'||
rem[i] == 'I'||rem[i] == 'i'||rem[i] == 'O'||rem[i] == 'o'||
rem[i] == 'U'||rem[i] == 'u')
{
count++;
if(count < 4)
continue;
else
{
temp = temp + rem.substr(0,i+1) + "^";
rem = rem.substr(i+1);
i = 0;
}
}
}
cout<<temp+rem;
getch();
return 0;
}
small correction
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
using namespace std;
int main()
{
string s = "greateriibblizing";
string temp ="";
string rem = s;
int count = 0;
for(int i = 0; i < rem.length(); i++)
{
if(rem[i] == 'A' ||rem[i] == 'a'||rem[i] == 'E'||rem[i] == 'e'||
rem[i] == 'I'||rem[i] == 'i'||rem[i] == 'O'||rem[i] == 'o'||
rem[i] == 'U'||rem[i] == 'u')
{
count++;
if(count < 4)
continue;
else
{
temp = temp + rem.substr(0,i+1) + "^";
rem = rem.substr(i+1);
i = -1; ///this should be -1 rather than 0
}
}
}
cout<<temp+rem;
getch();
return 0;
}
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class ReplaceVowels {
public static void main(String[] args) {
Map<String, Boolean> vowels = new HashMap<String, Boolean>();
vowels.put("a", true);
vowels.put("e", true);
vowels.put("i", true);
vowels.put("o", true);
vowels.put("u", true);
vowels.put("A", true);
vowels.put("E", true);
vowels.put("I", true);
vowels.put("O", true);
vowels.put("U", true);
Scanner terminal = new Scanner(System.in);
String input = terminal.nextLine();
terminal.close();
StringBuilder output = new StringBuilder();
for (int k = 0; k < input.length(); k++) {
if (vowels.get(input.charAt(k) + "") != null) {
output.append(input.charAt(k)).append("^");
} else {
output.append(input.charAt(k));
}
}
System.out.println(output.toString());
}
}
Output:
greateribblizing
gre^a^te^ri^bbli^zi^ng
def letter():
a = "greateribblizing"
letters = ['a','e','i','o','u','A','E','I','O','U']
count = 0
position_last_vogal = 0
string_final = ''
for i in range(len(a)):
if a[i] in letters:
count += 1
position_last_vogal = i
if count >= 3:
break
string_final = a[:position_last_vogal+1]
for i in range(position_last_vogal+1,len(a)):
if a[i] in letters:
string_final += a[i] + "^"
else:
string_final += a[i]
return string_final
letter()
#just substitute a for raw_input
def letter():
a = "greateribblizing"
letters = ['a','e','i','o','u','A','E','I','O','U']
count = 0
position_last_vogal = 0
string_final = ''
for i in range(len(a)):
if a[i] in letters:
count += 1
position_last_vogal = i
if count >= 3:
break
string_final = a[:position_last_vogal+1]
for i in range(position_last_vogal+1,len(a)):
if a[i] in letters:
string_final += a[i] + "^"
else:
string_final += a[i]
return string_final
letter()
substitute a with raw_input
- Misha October 16, 2014