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.
Vincoli
0 ≤ length of text ≤ 10,000 (ASCII characters)
Esempi
Input:
text = "Hello World"
Output atteso:
expected = 2
Input:
std::string text = "Hello World";
Output atteso:
long long expected = 2;
Input:
string text = "Hello World";
Output atteso:
long expected = 2;
Spiegazione
H and W are uppercase: 2.
Input:
text = "no caps here!"
Output atteso:
expected = 0
Input:
std::string text = "no caps here!";
Output atteso:
long long expected = 0;
Input:
string text = "no caps here!";
Output atteso:
long expected = 0;
Spiegazione
There are no uppercase letters: 0.
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Scan the text once and notice only letters A through Z count.
Suggerimento 2
Check each character’s case directly instead of comparing against words or splitting the string.
Suggerimento 3
Remember lowercase letters, digits, spaces, and punctuation do not contribute.
Complessità attesa
O(n) time, O(1) extra space
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.