公式

A - 旅の記録 / Travel Records 解説 by admin

swe-2-high

Explanation

The answer is the number of uppercase letters in \(S\). Scan the string character by character and increment a counter whenever the character lies between A and Z. Lowercase letters fall outside this range and are excluded automatically.

The program keeps a counter \(c\), checks 'A' <= ch <= 'Z' for each character of \(S\), and prints \(c\). This counts exactly the uppercase letters, matching the definition of foreign-country visits.

Complexity

Each of the \(N\) characters is inspected once, giving \(O(N)\) time and \(O(N)\) space to store the string.