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

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?