编程介的小学生 2017-06-04 13:24 采纳率: 20.5%
浏览 705
已采纳

Jumping the Queue

Problem Description
The beginning of a winter break near Spring Festival is always the beginning of a peak period of transportation. If you have ever tried to get a train ticket at that time, you must have witnessed the endless queues in front of every ticket box window. If a guy has seen his friend in a queue, then it is very much likely that this lucky guy might go straight to his friend and ask for a favor. This is called "jumping the queue". It is unfair to the rest of the people in the line, but, it is life. Your task is to write a program that simulates such a queue with people jumping in every now and then, assume that, if one in the queue has several friends asking for favors, he would arrange their requests in a queue of his own.

Input
There will contain one or more test cases. Each test case begins with the number of groups n (1<= n <=1000). Then n group descriptions follow, each one consisting of the number of friends belonging to the group and those people's distinct names. A group is a friend group. People in one group are friend with each other. A name is a string of up to 4 characters chosen from {A, B, ..., Z, a, b, ..., z}. A group may consist of up to 1000 friends. You may assume that there is no one belong to two different groups.
Finally, a list of commands follows. There are three different kinds of commands:

● ENQUEUE X - Mr. or Ms. X goes into the queue
● DEQUEUE - the first person gets the ticket and leave the queue
● STOP - end of test case

The input will be terminated by a value of 0 for n.

Output
For each test case, first print a line saying "Scenario #k", where k is the number of the test case. Then, for each DEQUEUE command, print the person who just gets a ticket on a single line. Print a blank line between two test cases, but no extra line at the end of output.

Sample Input
2
3 Ann Bob Joe
3 Zoe Jim Fat
ENQUEUE Ann
ENQUEUE Zoe
ENQUEUE Bob
ENQUEUE Jim
ENQUEUE Joe
ENQUEUE Fat
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
2
5 Anny Jack Jean Bill Jane
6 Eva Mike Ron Sony Geo Zoro
ENQUEUE Anny
ENQUEUE Eva
ENQUEUE Jack
ENQUEUE Jean
ENQUEUE Bill
ENQUEUE Jane
DEQUEUE
DEQUEUE
ENQUEUE Mike
ENQUEUE Ron
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
0

Sample Output
Scenario #1
Ann
Bob
Joe
Zoe
Jim
Fat

Scenario #2
Anny
Jack
Jean
Bill
Jane
Eva

  • 写回答

1条回答 默认 最新

  • devmiao 2017-06-04 18:34
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R