Algorithm title: Hdu 1022 Train Problem I Stack

Source: Internet
Author: User

As the new term comes, the Ignatius Train station is very busy. A lot of student want to get back to school by train (because the trains in the Ignatius train station are the fastest all O Ver the world ^v^). But Here comes a problem, there are only one railway where all the trains stop. So all of the trains come in from one side and get out of the other side. For this problem, if train a gets into the railway I, and then train B gets into the railway before a train, tr Ain A can ' t leave until train B leaves. The pictures below figure out the problem. Now the problem for are, there are at most 9 trains in the station, all the trains has a ID (numbered from 1 to N), the Trains get into the "railway in" Order O1, your task are to determine whether the trains of the "can get out of" an order O2.

Input

The input contains several test cases. Each test case consists of a, the number of trains, and two strings, the order of the trains come in:o1, and the Order of the trains Leave:o2. The input is terminated by the ' End of file '. More details in the Sample Input.

Output

The output contains a string "No." If you can ' t exchange O2 to O1, or your should output a line contains "Yes.", and then O Utput your way in exchanging the order (you should output ' in ' for a train to the getting, and ' out ' for a railway Getting out of the railway). Print a line contains "FINISH" for each test case. More details in the Sample Output.

Sample Input

3 123 321 3 123 312

Sample Output

Yes. Out FINISH No. FINISH

Hint

So now train 3 are at the top of the railway, so train 3 can leave a, then train 2 and train 1.

In the second Sample input, we are should let train 3 leave I, so we have to let train 1 get in, then train 2 and train 3.

Now we can let train 3 leave.

But after so we can ' t let train 1 leave before train 2, because train 2 are at the top of the railway at the moment.

So we output "No."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.