#K58287. Custom Alphabet Sorting
Custom Alphabet Sorting
Custom Alphabet Sorting
You are given a custom alphabet order and a list of words. The custom alphabet is a permutation of the 26 lowercase English letters. Formally, let \(A\) be a string of length \(26\) containing each lowercase letter exactly once. You need to sort a list of words in ascending order according to this custom alphabet.
For example, if the custom alphabet is given by \(A = \texttt{zyxwvutsrqponmlkjihgfedcba}\), then for the words ["apple", "banana", "cherry"], the sorted order will be ["cherry", "banana", "apple"] because the order of letters is reversed compared to the standard alphabet.
Your program should read input from stdin and write the results to stdout.
inputFormat
The input is given in the following format:
- The first line contains a string \(A\) representing the custom alphabet order which is exactly 26 unique lowercase letters.
- The second line contains an integer \(n\) representing the number of words.
- The following \(n\) lines each contain a word composed of lowercase letters.
outputFormat
Output the \(n\) words sorted according to the custom alphabet order. Each word should be printed on a new line.
## samplezyxwvutsrqponmlkjihgfedcba
3
apple
banana
cherry
cherry
banana
apple
</p>