编程介的小学生 2017-02-22 14:41 采纳率: 20.5%
浏览 916
已采纳

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

4
1 4 2 3 0
2 1 3 4 0
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
246
5 6 7 2 7 1 2 4 3 5 3 1 7 1 6 4 0
8 6 2 6 4 8 7 8 2 3 5 8 3 5 1 4 0
0

Sample Output

Case 1:
2 3
3 4 1 4 2 1
NULL
Case 2:
1 5 3 5 7 6 7 7 2 7 1 4 3 1
4 8 8 8 5 8 3 4 6 3 6 6 2 2
5 4 2 1
Case 3:
A

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-02-28 21:19
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘