2 shunfurh shunfurh 于 2017.09.11 14:01 提问

The Party's in Dolores's Driveway

Dolores's house has an unusual semi-circular driveway that can accommodate 26 cars in a single file, with exits at the front and the back. This is nice because when she hosts a party because everyone can park in the driveway. However, it causes complications when a guest wants to leave, because other guests with cars blocking that person must move their cars temporarily. Her guests take this in stride, and make a game out of the nuisance. When someone leaves, those cars that must move return to the driveway in reverse order. Since there are two ways for the leaving car to exit (through the front or rear exit), the cars on the shorter path to an exit must move (and return in reverse order). If the car that wants to leave is exactly in the middle, the front cars (on the left) must move.

For example, suppose the initial driveway configuration is represented as ABCDEFG. Suppose further that the owner of car E decides to leave. Then the owners of cars F and G must move (since they're on the shorter path to an exit) to make room for E to leave, and then return to the driveway in reverse order. The new driveway configuration will be ABCDGF. Suppose now C wants to leave. Here, A and B have to move (since they're on the shorter path to an exit) , with the resulting configuration BADGF. Let's say that now D wants to leave. In this case, B and A must move (since both exit paths are of equal length, and A and B are on the path to the front exit). The resulting configuration is ABGF.

Write a program to simulate this party game.

Input

Each data set begins with a line containing only a string of uppercase letters, representing the initial order of cars in the driveway as described above. The string will contain at least one letter, and no letter is duplicated. The next line contains an integer n >= 0. The next n lines each contain only a single uppercase letter, indicating the next car to leave the party; this letter is guaranteed to represent one of the remaining cars at the party. Your program should stop processing data sets when it reaches an initial driveway order of STOP.

Output

Begin the output for each data set by indicating the data set number and the initial order of cars in the driveway. As each car leaves, output the new car order. Follow the output format indicated in the Sample Output. Leave a blank line between the output for different data sets.

Sample Input

ABCDEFG
3
E
C
D
HIWORLD
1
H
STOP

Sample Output

Dataset #1: The initial order is ABCDEFG.
After E leaves, the order is ABCDGF.
After C leaves, the order is BADGF.
After D leaves, the order is ABGF.

Dataset #2: The initial order is HIWORLD.
After H leaves, the order is IWORLD.

2个回答

caozhy
caozhy   Ds   Rxr 2017.09.13 00:49
已采纳
shen_wei
shen_wei   Ds   Rxr 2017.09.12 16:52
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
1291The Party's in Dolores's Driveway
The Partys in Doloress Driveway Time Limit: 1 Seconds     Memory Limit: 32768 K
fjnu 1291 The Party's in Dolores's Driveway
DescriptionDoloress house has an unusual semi-circular driveway that can accommodate 26 cars in a single file, with exits at the front and the back. This is nice because when she hosts a party be
二分图(Arpa’s overnight party and Mehrdad’s silent entering,cf 741C)
看了别人代码才会写的,所以只能说说自己的理解吧。 就是说建一个图,有2n个点,然后给所有(2i-1)和(2i)连一条边(1(2i-1)和(2i)的食物一定不同。而任意的连续3人一定包含了某对(2i-1)和(2i)。 看完题只能想到图论呀,图论只能想到二分图呀,二分图只能想到构造呀,然后不知道该怎么构造呀。。。然后就乱搞呀。。。其实应该顺着构造的思路走下去,不该迷路的。。。有一些
Light OJ - 1008 - Fibsieve`s Fantabulous Birthday 题解
就是计算特殊长方形坐标的问题,这类题目需要的是细心,细心,再细心,然后推导摸索出公式来, 题目如下: Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not havin
杭电OJ-- 2095 find your present (依然很水)
Problem Description In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them wil
2095:find your present (2)
Problem Description In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them wil
杭电 HDU ACM 1563 Find your present!
Find your present! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3096    Accepted Submission(s): 2051 Problem Description In the new
CodeForces 906C Party(状态压缩+dfs)
日常打cf……         大致题意:给你一堆一对对的关系,然后每一个关系对代表两个人认识。然后你每次可以选择一个人i,让i认识的所有人都相互认识,即i把介绍自己所有的朋友给其他人。然后现在问你最少需要选择多少个这样的i,使得所有的人都相互认识。         看到只有22的数据范围,很容易想到状态压缩,但是如何利用这个状态压缩却没那么好考虑。如果考虑状态压缩dp,显然无法表示连通的状态。于是考虑用搜索,22个点要么最后被选要么没有,做多2^22=400W+,在承受范围内。然后就是看如何处理这个关系了
GYM 100971 G.Repair(水~)
Description 给出一个a1*b1和一个a2*b2的照片,问是否可以摆到一个a*b的相框里 Input 输入六个整数a,b,a1,b1,a2,b2(1<=a,b,a1,b1,a2,b2<=1e9) Output 如果能放下则输出YES,否则输出NO Sample Input 12 20 14 7 5 6 Sample Output YES Solution 两张画正
Light OJ:1008 Fibsieve's Fantabulous Birthday(规律)
Description Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year. Among these gifts th