No.8116 TCP Sort
Problem Statement
You are given a string $S$ consisting of C, P, and T. Rearrange the characters of $S$ so that the following $2$ conditions are satisfied, and output the result.
- Every
Tin $S$ appears to the left of everyC. - Every
Cin $S$ appears to the left of everyP.
Input
$S$
- $S$ is a string of length between $1$ and $100$, inclusive, consisting of
C,P, andT.
Output
Output the characters of $S$ rearranged so that the conditions in the problem statement are satisfied. However, if there are multiple rearrangements satisfying the conditions, output the lexicographically smallest one among them.
It can be proved that at least $1$ rearrangement satisfying the conditions exists.
Sample
Sample 1
Input
PCT
Output
TCP
The only rearrangement of PCT satisfying the conditions is TCP, so there is $1$ such rearrangement.
Sample 2
Input
CCTTPPCPCT
Output
TTTCCCCPPP
The only rearrangement of CCTTPPCPCT satisfying the conditions is TTTCCCCPPP, so there is $1$ such rearrangement.
Sample 3
Input
PCPCPCCPCC
Output
CCCCCCPPPP
The only rearrangement of PCPCPCCPCC satisfying the conditions is CCCCCCPPPP, so there is $1$ such rearrangement.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tatyam