Official

A - Rearranging ABC Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).


Solution 1: try all possible solutions

The strings that one can rearrange to match it with ABC are the following six: ABC, ACB, BAC, BCA, CAB, and CBA. It is sufficient to check if the string \(S\) given as input coincides with one of them.

Sample code (Python3)

S = input()
if S in ["ABC", "ACB", "BAC", "BCA", "CAB", "CBA"]:
    print("Yes")
else:
    print("No")

Solution 2: Simplify the condition

Since \(S\) has a length of \(3\), the answer is Yes if and only if \(S\) contains all of the characters A, B, and C. Thus, the answer is Yes if these are all contained in \(S\), and No otherwise.

Sample code (Python3)

S = input()
if "A" in S and "B" in S and "C" in S:
    print("Yes")
else:
    print("No")

posted:
last update: