#C10327. Custom Sort String
Custom Sort String
Custom Sort String
You are given two strings order
and s
. Your task is to rearrange the characters in s
so that the characters that appear in order
come first in the order specified by order
, and the remaining characters appear at the end in their original relative order. If a character in s
does not appear in order
, it should simply be appended after all characters from order
.
Note: The order for characters not included in order
remains the same as their original appearance in s
.
Formally, given two strings $order$ and $s$, sort the characters in $s$ so that for any two characters $x$ and $y$: if $x$ appears before $y$ in $order$, then $x$ should come before $y$ in the resulting string. Characters not appearing in $order$ will maintain their relative order as in $s$.
inputFormat
The input consists of two lines:
- The first line contains the string
order
. - The second line contains the string
s
.
Both strings consist of printable characters.
outputFormat
Output a single line containing the rearranged string.
## samplecba
abcd
cbad