编程介的小学生 2017-07-30 11:55 采纳率: 20.5%
浏览 639
已采纳

A Card Trick

The following card trick is performed by a Magician and her Assistant. The Assistant asks a member of the audience to choose 5 cards from a standard deck of 52 cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K of C[lubs], D[iamonds], H[earts] and S[pades]). The Assistant returns one of the cards to the audience member and then hands the remaining cards to the Magician, one at a time. After suitable mumbo-jumbo, the Magician identifies the (fifth) card held by the audience member.

The Magician determines the card as follows:

The order of the cards in the deck is determined first by the value and for cards of the same value by the suit (both in the order given above). So the total order of cards is: AC, AD, AH, AS, 2D, ... , KH, KS

Remember the suit and value of the first card.
Among the remaining three cards find the position of the smallest card (in the above order). Add this position (1, 2, or 3) to the value of the first card.
If the larger two of the last three cards are not in order, add 3 to the result of step 2.
The missing card has the same suit as the first card and value that computed in step 3 wrapping around if necessary.
For example:

QH, 10D, 10C, 4D

Smallest of the last 3 cards is 4D in place 3. 10D and 10C are out of order so add 3 + 3 to Q. Wrapping around the missing card is 5H.

This problem is to write a program to perform the function of the Assistant.

Input

The first line of the input consists of a positive integer n, which is the number of datasets that follow. Each of the n following lines contain one data set. The dataset is a sequence of 5 cards separated by a space. Each card is given by a one or two character value and a one character suit as described in the first paragraph.

Output

For each dataset, the output on separate lines is an ordering of the 5 input cards as shown in the sample output. The first card in the sequence is the card to be returned to the audience member. The remaining cards are those given to the Magician (in the order given to the Magician). There may be more than one solution to some problems (but that is not to say there will be). In cases such as these, output the smallest one, determine the order base at the order of cards given above. For instance 10D 4D QH 10C 5H is also a solution to the first problem below but 5H QH 10D 10C 4D < 10D 4D QH 10C 5H.

Sample Input

2
4D 5H 10C 10D QH
7H 5C KS 6C 8D

Sample Output

Problem 1: 5H QH 10D 10C 4D
Problem 2: 6C 5C 7H 8D KS

  • 写回答

2条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线