编程介的小学生 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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码