公式

A - 財布の中身 / Contents of the Wallet 解説 by admin

swe-2-high

Explanation

We just need to check whether C and B each appear at least once in \(S\). The program uses s.find('C') and s.find('B'); find returns string::npos when the character is absent, so comparing against that tells us whether each exists. It prints Yes only when both are found.

Why it works: since \(S\) consists solely of C and B, “C occurs” is equivalent to “there is at least one coin”, and “B occurs” is equivalent to “there is at least one bill”. Checking both matches the problem’s condition exactly.

Each find scans the string once, so the time is \(O(N)\) and storing the input string costs \(O(N)\) space.