求解Card Game -Kitty Fishing

meiwenhua 2002-07-15 09:25:47
Card Game -Kitty Fishing


There is a simple two-player card game called "Kitty Fishing". When the game begins, player A and B have the same number of cards. Then each gives out one card in turn. Each card given out on the table should be laid overlapped one by one. When the card newly given out finds a card which has the same value on the table, the player who gives out the card will take the cards between the two same cards following the order the cards on the table, and put them to the back of his cards. The same player continues to give out next cards. Player giving a card called a turn. Note: Do not change the order of your cards.

The following is an example.

At the beginning:
A has cards 1,4,2,3 and B has cards 2,1,3,4

First: A gives out 1.
A:4,2,3
B:2,1,3,4
Cards on the table:1.

Second:B gives out 2.
A:4,2,3
B:1,3,4
Cards on the table:1,2

Third:A gives out 4.
A:2,3
B:1,3,4
Cards on the table:1,2,4

Forth:B gives out 1.
A:2,3
B:3,4
Cards on the table:1,2,4,1

The card '1' given out by B is the same as the first one of the cards on the table. So B takes the cards following the turn of '1,4,2,1'. Then it will be:
A:2,3
B:3,4,1,4,2,1
Cards on the table:NULL

In this example, A and B have four turns.

If one of the players has given out all of his cards, he will lose the game, and the other one is the winner. The game is over.

Write a program that will play the game of "Kitty Fishing"..

Input

The input contains one or more data sets. Each data set consists of three lines: The first line contains an integer which gives out the turns you should play, and the next two lines are cards which A and B have. Each one's cards will be ended with the number 0.
A line which contains a single 0 will end the input. No input lines follow that line.

Output

If the game has been over before the turns, just write out the winner's name. If the game has not been over, write out the cards two players have in the order in their hands and the cards on the table.

Sample Input


30

5 8 5 6 5 7 3 4 6 2 1 7 7 1 2 1 0

3 8 7 8 8 5 6 3 6 2 3 2 4 4 1 4 0

0


Sample Output


Case 1:

1 5 7 3 5 3 3 6 6 1 1

4 8 8 8 5 8 6 7 5 6 2 2 4 7 2 1 3 4

2 7 4

...全文
89 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaojinn 2002-11-28
  • 打赏
  • 举报
回复
#include "test.h"
class node
{
int r,l,h;
node *next;
};

class linkedlist
{
public:
linkedlist(){head=0; isempty=true;}
void insert(int r,int h,int l);


private:
node *head,*tail;
bool isempty;
};

/*void linkedlist::insert(int r,int h,int l)
{
node *temp;
temp=new node[1];
temp->h=h;
temp->l=l;

if(isempty)
head=tail=temp;

*/

void main()
{
test tes;
}
meiwenhua 2002-11-28
  • 打赏
  • 举报
回复
继续啊!!
meiwenhua 2002-07-16
  • 打赏
  • 举报
回复
快来回答啊!!
jack4liang 2002-07-16
  • 打赏
  • 举报
回复
这里面有关查找的算法,大家认为什么方法比较好?
atlantis13579 2002-07-15
  • 打赏
  • 举报
回复
有什么难啊,用队列和栈模拟这个过程就行了
radioheads 2002-07-15
  • 打赏
  • 举报
回复
这可是那年最简单的题

33,007

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧