← 返回 google 的题目列表Custom Sort String Variant
类型:online_judge
Problem: Custom Sort String
You are given two strings order and s.
All characters in order are unique and define a custom ordering of characters.
Rearrange the characters in s such that:
If characters a and b both appear in order, and a appears before b in order, then all occurrences of a must appear before all occurrences of b in the result.
Characters that do not appear in order should be placed at the end of the result while preserving their relative order from s.
Return the rearranged string.
Input Format
Two lines:
order
s
Output Format
Print one string, the custom-sorted version of s.
Constraints
1 <= len(order) <= 26
1 <= len(s) <= 10^5
order consists of unique lowercase English letters
s consists of lowercase English letters
Example
Input:
cba
abcd
Output:
cbad
Explanation: c, b, and a are ordered according to order; d is not in order, so it is placed at the end.
Example
Input
cba
abcd
Output
cbad