1291The Party's in Dolores's Driveway

The Party's in Dolores's Driveway

Time Limit: 1 Seconds     Memory Limit: 32768 K

Total Submit:221     Accepted:87


Description

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.

 

Source

2000 ACM Southeast Regional

 

Source:

#include<iostream>
using namespace std;
int main()
{
	char a[30],w,t;int n,i,j,m,k,l;l=1;
	while(cin>>a)
	{
		int b[27]={0};
		if(strcmp(a,"STOP")==0)
			break;
		printf("Dataset #%d:  The initial order is %s./n",l,a);
		l++;
         cin>>n;
		 m=strlen(a);
		 while(n--)
		 {
			 cin>>w;
			 i=0;
			 while(a[i]!='/0')
			 {
				 if(a[i]==w)
					 break;
				 i++;
			 }
			 j=i;
			 if(i+1>(m+1)/2)
			 {
				 k=m-1;
				 a[i]=a[k];
				 i++;
				 k--;
				 while(k>i)
				 {
					 t=a[i];
					 a[i]=a[k];
					 a[k]=t;
					 i++;
					 k--;
				 }
				 a[m-1]='/0';
			 }
			 else
			 {
				 while(a[i]!='/0')
				 {
					 a[i]=a[i+1];
					 i++;
				 }
				 k=0;
				 j--;
				 while(j>k)
				 {
					 t=a[j];
					 a[j]=a[k];
					 a[k]=t;
					 j--;
					 k++;
				 }
			 }
			 m--;
			 printf("After %c leaves, the order is %s./n",w,a);
		 }
		 printf("/n");
	}
	return 0;
}

 

 

用土办法了,呵呵,没有科技含量,不懂哪位能指点一下下

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可 6私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值