|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||118||66||65||57.018%|
We know the normal alphabetical order of the English alphabet, and we can then sort words or other letter sequences. For instance these words are sorted:
The standard rules for sorting letter sequences are used:
The Gorellians, at the far end of our galaxy, have discovered various samples of English text from our electronic transmissions, but they did not find the order of our alphabet. Being a very organized and orderly species, they want to have a way of ordering words, even in the strange symbols of English. Hence they must determine their own order. Unfortunately they cannot agree, and every Gorellian year, they argue and settle on a new order.
For instance, if they agree on the alphabetical order
then the words above would be sorted as
The first letters of the words are in their alphabetical order. Where words have the same prefix, the first differing letter determines the order, so the order goes ANY, then ANTLER, since Y is before T in their choice of alphabet. Still HOWEVER comes after HOW, since HOW is a prefix of HOWEVER.
Dealing with the different alphabetical orders each year by hand (or tentacle) is tedious. Your job is to implement sorting with the English letters in a specified sequence.
The input will contain one or more datasets. Each dataset will start with a line containing an integer n and a string s, where s is a permutation of the English uppercase alphabet, used as the Gorellians' alphabet in the coming year. The next n lines (1 ≤ n ≤ 20) will each contain one non-empty string of letters. The length of each string will be no more than 30. Following the last dataset is a line containing only 0.
The first line of output of each dataset will contain "year " followed by the number of the dataset, starting from 1. The remaining n lines are the n input strings sorted assuming the alphabet has the order in s.
8 UVWXYZNOPQRSTHIJKLMABCDEFG ANTLER ANY COW HILL HOW HOWEVER WHATEVER ZONE 5 ZYXWVUTSRQPONMLKJIHGFEDCBA GO ALL ACM TEAMS GO 10 ZOTFISENWABCDGHJKLMPQRUVXY THREE ONE NINE FIVE SEVEN ZERO TWO FOUR EIGHT SIX 0
year 1 WHATEVER ZONE HOW HOWEVER HILL ANY ANTLER COW year 2 TEAMS GO GO ALL ACM year 3 ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE