Условие
Count how many characters in text are uppercase English letters A–Z.
Implement count_uppercase(text).
Input
text: The text to inspect.
Output
Return the number of uppercase letters.
Ограничения
0 ≤ length of text ≤ 10,000 (ASCII characters)
Примеры
Ввод:
text = "Hello World"
Ожидаемый вывод:
expected = 2
Ввод:
std::string text = "Hello World";
Ожидаемый вывод:
long long expected = 2;
Ввод:
string text = "Hello World";
Ожидаемый вывод:
long expected = 2;
Пояснение
H and W are uppercase: 2.
Ввод:
text = "no caps here!"
Ожидаемый вывод:
expected = 0
Ввод:
std::string text = "no caps here!";
Ожидаемый вывод:
long long expected = 0;
Ввод:
string text = "no caps here!";
Ожидаемый вывод:
long expected = 0;
Пояснение
There are no uppercase letters: 0.
Как подступиться
Сначала попробуйте сами, затем открывайте подсказки по одной.
Подсказка 1
Scan the text once and notice only letters A through Z count.
Подсказка 2
Check each character’s case directly instead of comparing against words or splitting the string.
Подсказка 3
Remember lowercase letters, digits, spaces, and punctuation do not contribute.
Ожидаемая сложность
O(n) time, O(1) extra space
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.