fjnu 1291 The Party's in Dolores's Driveway
来源:互联网 发布:酒心巧克力 知乎 编辑:程序博客网 时间:2024/04/29 23:38
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
ABCDEFG3ECDHIWORLD1HSTOP
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.
KEY:这题要注意的是,车退出后的进入顺序,他是先出先进,这就让人自然想到了队列;
#include<iostream>
using namespace std;
class Queue
...{
int front;
int rear;
char elem[30];
public:
Queue()
...{
front=rear=1;
}
void EnQueue(char x);
char DeQueue();
int IsEmpty();
};
void Queue::EnQueue(char x)
...{
elem[rear++]=x;
}
char Queue::DeQueue()
...{
return elem[front++];
}
int Queue::IsEmpty()
...{
if(front==rear) return 1;
else return 0;
}
char a[30];
int len;
void move(char c)
...{
Queue Q;
len=strlen(a);
int i,pos;
for(i=0;i<len;i++)
if(a[i]==c)
...{
pos=i;
break;
}
if(pos<=(len-1)/2)
...{
for(i=0;i<pos;i++)
...{
Q.EnQueue(a[i]);
}
while(!Q.IsEmpty())
...{
a[i]=Q.DeQueue();
i--;
}
strcpy(a,&a[1]);
}
else
...{
for(i=len-1;i>pos;i--)
...{
Q.EnQueue(a[i]);
}
while(!Q.IsEmpty())
...{
a[i]=Q.DeQueue();
i++;
}
a[i]='
- fjnu 1291 The Party's in Dolores's Driveway
- 1291The Party's in Dolores's Driveway
- fjnu 1749 Plant's Multiplication
- PKU_ACM_2388_Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- hdu1157Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- hdu1157Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- SQLite语法 DETACH DATABASE
- SQLite语法 DETACH DATABASE
- fjnu 1461 Factorials
- 数据库中时间的替换
- SQLite语法 DELETE
- fjnu 1291 The Party's in Dolores's Driveway
- SQLite语法 CREATE VIEW
- SQLite语法 CREATE TRIGGER
- SQLite语法 CREATE TABLE
- SQLite语法 CREATE INDEX
- java ftp 客户端(apache jakarta commons net ftp)的bug[原创][Bug]
- SQLite语法 COPY
- SQLite语法 COMMIT TRANSACTION
- SQLite语法 comment