-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindthevowels.cpp
More file actions
47 lines (40 loc) · 1.12 KB
/
Findthevowels.cpp
File metadata and controls
47 lines (40 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <iostream>
using namespace std;
vector<int> vowelIndices(const string& word)
{
vector<int>result;
for (int i = 0; i < word.size(); i++)
{
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u' || word[i] == 'y' || word[i] == 'A' || word[i] == 'E' || word[i] == 'I' || word[i] == 'O' || word[i] == 'U' || word[i] == 'Y')
{
result.push_back(i + 1);
}
}
return result;
}
int main() {
vector<int>ss = vowelIndices("Apple");
for (int i = 0; i < ss.size(); i++)
{
cout << ss[i];
}
return 0;
}
/*
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
So given a string "super", we should return a list of [2, 4].
Some examples:
Mmmm => []
Super => [2,4]
Apple => [1,5]
YoMama -> [1,2,4,6]
NOTES
Vowels in this context refers to: a e i o u y (including upper case)
This is indexed from [1..n] (not zero indexed!)
Fundamentals
*/