P29690 [洛谷] [COCI2011-2012#3] DIGITALNA
入门
题目描述

Problem Background

Since the answer is not unique, this problem uses SPJ (Special Judge) for evaluation.

Problem Description

Recently, Mirko's grandparents had to switch from analog to digital TV receivers. On their old analog receiver, they could only watch two channels—BLJTV1 and BLJTV2. After switching to a digital receiver, they gained dozens of new channels, but they still want to watch only the previous two channels. They asked Mirko to adjust the channel menu so that BLJTV1 is on the first channel and BLJTV2 is on the second channel. Upon startup, the digital receiver creates a list of available channels. All channels are unique, and the list always includes BLJTV1 and BLJTV2. Mirko found the remote control and started adjusting the menu. The menu contains the channel list and an arrow indicating the currently selected channel. Upon entering the menu, the arrow marks the first channel in the list. There are four operations in the menu, each represented by a number preceding it in the sequence:

  1. Move the arrow down one position (from channel $i$ to channel $i+1$);
  2. Move the arrow up one position (from channel $i$ to channel $i-1$);
  3. Move the arrow and the selected channel down one position (swap channels $i$ and $i+1$, the arrow ends up at channel $i+1$);
  4. Move the arrow and the selected channel up one position (swap channels $i$ and $i-1$, the arrow ends up at channel $i-1$).

The menu is stable, so invalid commands (such as moving the arrow beyond the channel list) will be ignored.

Write a program that, given a channel list, outputs a sequence of any operations that, when executed, will place BLJTV1 on the first position and BLJTV2 on the second position in the channel list. Additionally, the length of this sequence should be less than $500$. The order of all other channels is arbitrary.

Input Format

The input consists of $n+1$ lines.

The first line contains an integer $n$, indicating the number of channels.
The following $n$ lines each contain a string $s$, representing the name of a channel.

The input guarantees that BLJTV1 and BLJTV2 are among the channels, and at least one feasible operation sequence exists.

Output Format

Output a single line containing a string that represents the sequence of operations that achieves the requirement.

Sample Input and Output

Sample Input #1

3
ABC
BLJTV1
BLJTV2

Sample Output #1

33

Sample Input #2

4
ABC1
ABC02
BLJTV2
BLJTV1

Sample Output #2

11144411144

Sample Input #3

4
ABC1
ABC02
BLJTV2
BLJTV1

Sample Output #3

33144413

Notes

[Data Range]

For all data, $2 \leqslant n \leqslant 100$, the channel names are no longer than $10$ characters and consist only of uppercase English letters and digits.

[Problem Source]

This problem is from COCI 2011-2012 CONTEST 3 T1 DIGITALNA, configured according to the original problem data, with a full score of $50$ points.

Translated and provided by Eason_AC.

Thanks to yzy1 for providing the SPJ for this problem.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 ABC BLJTV1 BLJTV2
样例输出
33