Official

A - 旅の記録 / Travel Records Editorial by admin Editorial for printing

swe-2-high

Explanation

This problem simply asks for the number of uppercase English letters contained in \(S\).

Algorithm

  1. Read \(N\) and the string \(S\) from input.
  2. For each character \(c\) of \(S\), check whether \(c\) lies between 'A' and 'Z' (i.e., is an uppercase letter), and count how many characters satisfy this.
  3. Print the count.

Proof of correctness

The algorithm scans every character of \(S\) exactly once and tests each with the comparison 'A' <= c <= 'Z'. In ASCII (the character encoding used by C++ and Python), uppercase letters occupy the contiguous code range ['A','Z'], so this test is equivalent to “\(c\) is an uppercase English letter.” Hence the counter equals exactly the number of uppercase letters in \(S\), and the output is correct.

By the constraints, \(S\) consists only of uppercase and lowercase English letters, so lowercase letters are automatically excluded.

Complexity

  • Time: \(O(N)\) — each character is examined once.
  • Space: \(O(N)\) for storing the input string \(S\); only \(O(1)\) additional auxiliary space.

Since \(N \leq 100\), this is more than fast enough.

posted:
last update: