|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||17||5||4||50.000%|
Jane and Tim are getting married. They are so compatible because they keep their shirts in their wardrobes in the same colour and size order. Jane has bought her own house so Tim will be moving in after they are married. His shirts will need to be merged in with hers, sorted by size then colour.
If you do a good job, they will make your solution available to other newly weds that are known to have similar habits, so you will be given more than one set of data to test.
Input consists of a number of scenarios. A scenario begins with a single number, W (0 < W <= 30) on a line of its own being the number of shirts belonging to the wife. If this number is 0, then it signals the end of input.
The number is followed by W lines, each line being two upper case letters. The letters represent the size and colour of a shirt. Sizes are S, M and L. Colours are B for Blue, K for blacK, N for browN, O for Orange, P for Purple, R for Red and W for White.
The next line is another single number, H (0 < H <= 30) on a line of its own being the number of shirts belonging to the husband.
The number is followed by H lines to represent the husband's shirts using the same two letter codes as for the wife.
Output consists of a single line for each scenario. The line contains all of the shirts from the input, separated by single spaces. The shirts are sorted firstly by size (small before medium before large) then by colour (alphabetical order of the representative letter).
5 SB SB SP MP MR 6 MB MK MP LK LN LW 0
SB SB SP MB MK MP MP MR LK LN LW