Problema
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.
Restrições
0 ≤ length of text ≤ 10,000 (ASCII characters)
Exemplos
Entrada:
text = "Hello World"
Saída esperada:
expected = 2
Entrada:
std::string text = "Hello World";
Saída esperada:
long long expected = 2;
Entrada:
string text = "Hello World";
Saída esperada:
long expected = 2;
Explicação
H and W are uppercase: 2.
Entrada:
text = "no caps here!"
Saída esperada:
expected = 0
Entrada:
std::string text = "no caps here!";
Saída esperada:
long long expected = 0;
Entrada:
string text = "no caps here!";
Saída esperada:
long expected = 0;
Explicação
There are no uppercase letters: 0.
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Scan the text once and notice only letters A through Z count.
Dica 2
Check each character’s case directly instead of comparing against words or splitting the string.
Dica 3
Remember lowercase letters, digits, spaces, and punctuation do not contribute.
Complexidade esperada
O(n) time, O(1) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.