编程介的小学生 2017-06-23 03:24 采纳率: 20.5%
浏览 736
已采纳

Counting Out

Problem Description
Consider this simple form of shuffling a deck of cards. Hold the deck face down and count to a certain number (say k), on each count taking one card from the top of the deck and placing it at the bottom. When you have finished counting, turn the top card (the k+1'th card) over and place it face up on the table. Thus cards are continually moved from the top of the deck to the bottom, even when you have fewer cards than your chosen number. Continue in this way until you have no more cards left. Thus if k was 4, you would move 4 cards, one by one, from the top of the deck to the bottom and turn over the fifth. You would then move the sixth, seventh, eighth and ninth cards to the bottom and expose the tenth. Note that the number of the exposed card is always one more than k; if k was nine you would expose every tenth card, and so on.

Write a program that will read in the chosen number (k) and details of a deck of cards and simulate this process. Remember that a standard deck (or pack) of cards contains 52 cards. These are divided into 4 suits - Spades, Hearts, Diamonds and Clubs. Within each suit there are 13 cards - Ace (A), 2-9, Ten (T), Jack (J), Queen (Q) and King (K).

Input
Input will consist of a series of scenarios. Each scenario will start with a number k (4 <= k <= 26) on a line by itself. This will be followed by the description of a deck. A deck will be specified on four lines with 13 cards on each line and with cards separated by exactly one space (see the example below). The cards are shown as they would be seen if they were face up, thus the last card in the sequence would be the top of the deck as far as you are concerned. The file will be terminated by a line consisting of a zero (0).

Output
Output will consist of a series of lines, one for each scenario in the input. Each line will consist of the last card played, in the format shown below.

Sample Input
4
H2 H7 SA HJ D4 S4 HT DJ C9 HQ CT H8 SQ
DQ S6 D2 H5 CJ CK HA D5 D9 H9 S8 D3 C4
S2 C5 CQ D8 DT C6 DK H4 CA C8 C2 SK C7
S5 H6 H3 S9 S7 C3 SJ S3 ST HK DA D6 D7
0

Sample Output
S8

  • 写回答

1条回答

  • threenewbee 2017-07-21 12:22
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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系统的硬盘