समस्या
Count how many characters in text are vowels: a, e, i, o, u in either uppercase or lowercase.
Implement count_vowels(text).
Input
text: The text to inspect (ASCII characters).
Output
Return the number of vowels.
सीमाएँ
0 ≤ length ≤ 10,000
उदाहरण
इनपुट:
text = "Hello World"
अपेक्षित आउटपुट:
expected = 3
इनपुट:
std::string text = "Hello World";
अपेक्षित आउटपुट:
long long expected = 3;
इनपुट:
string text = "Hello World";
अपेक्षित आउटपुट:
long expected = 3;
व्याख्या
e, o and o are vowels: 3.
इनपुट:
text = "AEIOU and y"
अपेक्षित आउटपुट:
expected = 6
इनपुट:
std::string text = "AEIOU and y";
अपेक्षित आउटपुट:
long long expected = 6;
इनपुट:
string text = "AEIOU and y";
अपेक्षित आउटपुट:
long expected = 6;
व्याख्या
A, E, I, O, U, a are vowels; y is not counted: 6.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Scan the text once and test each character against the vowel set.
संकेत 2
Treat uppercase and lowercase vowels as the same kind of letter.
संकेत 3
An empty string should simply return zero.
अपेक्षित जटिलता
O(n) time, O(1) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।