Official

B - Sandwich Number Editorial by en_translator


What conditions should be satisfied when the answer is Yes? Here are some of them:

  • The first character is an uppercase English letter
  • The latter character is an uppercase English letter
  • The other characters are digits

Is it enough? Not really. For example, input like A10000000B mistakenly yields Yes.

What follows the first English letter is “a string of length \(6\) that is a decimal representation of an integer between \(100000\) and \(999999\).” Thus, we also need the following conditions:

  • The length of \(S\) is \(1 + 6 + 1 = 8\)
  • The second character of \(S\) is not 0

Note that, without the latter, input like A012345B mistakenly yields Yes.

We have listed five necessary conditions. When “the length of \(S\) is \(8\),” “all but the first and last characters are digits,” and “the second character of \(S\) is not 0,” the second through seventh characters of \(S\) is always a string of length \(6\) that is a decimal representation of an integer between \(100000\) and \(999999\), so we can assert that these five conditions are not only necessary conditions but also sufficient conditions.

Therefore, the code that checks the five conditions will be accepted.

Sample code (C++)

Sample code (Python)

posted:
last update: