UVa 10205 Stack 'em Up (模拟)

10205 - Stack 'em Up

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1146

A standard playing card deck contains 52 cards, 13 values in each of four suits. The values are named2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. The suits are named Clubs, Diamonds, Hearts, Spades. A particular card in the deck can be uniquely identified by its value and suit, typically denoted<value> of <suit>. For example, "9 of Hearts" or "King of Spades". Traditionally a new deck is ordered first alphabetically by suit, then by value in the order given above.

The Big City has many Casinos. In one such casino the dealer is a bit crooked. She has perfected several shuffles; each shuffle rearranges the cards in exactly the same way whenever it is used. A very simple example is the "bottom card" shuffle which removes the bottom card and places it at the top. By using various combinations of these known shuffles, the crooked dealer can arrange to stack the cards in just about any particular order.

You have been retained by the security manager to track this dealer. You are given a list of all the shuffles performed by the dealer, along with visual cues that allow you to determine which shuffle she uses at any particular time. Your job is to predict the order of the cards after a sequence of shuffles.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Input consists of an integer n <= 100, the number of shuffles that the dealer knows. 52n integers follow. Each consecutive 52 integers will comprise all the integers from 1 to 52 in some order. Within each set of 52 integers,i in position j means that the shuffle moves the ith card in the deck to positionj.

Several lines follow; each containing an integer k between 1 and n indicating that you have observed the dealer applying the kth shuffle given in the input.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Assume the dealer starts with a new deck ordered as described above. After all the shuffles had been performed, give the names of the cards in the deck, in the new order.

Sample Input

1

2
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 52 51
52 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 1
1
2

Output for Sample Input

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

King of Spades
2 of Clubs
4 of Clubs
5 of Clubs
6 of Clubs
7 of Clubs
8 of Clubs
9 of Clubs
10 of Clubs
Jack of Clubs
Queen of Clubs
King of Clubs
Ace of Clubs
2 of Diamonds
3 of Diamonds
4 of Diamonds
5 of Diamonds
6 of Diamonds
7 of Diamonds
8 of Diamonds
9 of Diamonds
10 of Diamonds
Jack of Diamonds
Queen of Diamonds
King of Diamonds
Ace of Diamonds
2 of Hearts
3 of Hearts
4 of Hearts
5 of Hearts
6 of Hearts
7 of Hearts
8 of Hearts
9 of Hearts
10 of Hearts
Jack of Hearts
Queen of Hearts
King of Hearts
Ace of Hearts
2 of Spades
3 of Spades
4 of Spades
5 of Spades
6 of Spades
7 of Spades
8 of Spades
9 of Spades
10 of Spades
Jack of Spades
Queen of Spades
Ace of Spades
3 of Clubs

直接模拟。

完整代码:

/*0.012s*/

#include<bits/stdc++.h>
using namespace std;
const char* suit[4] = {"Clubs", "Diamonds", "Hearts", "Spades"};
const char* value[4] = {"Jack", "Queen", "King", "Ace"};  

char s[5];
int code[105][53], deck[53], tmp_deck[53];  

int main()
{
    int T, n, x, i, j;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        for (i = 1; i <= n; ++i)
            for (j = 1; j <= 52; ++j)
                scanf("%d", &code[i][j]);
        getchar();
        for (i = 1; i <= 52; ++i) deck[i] = i;
        while (gets(s) && s[0])
        {
            sscanf(s, "%d", &x);
            for (i = 1; i <= 52; ++i)
                tmp_deck[i] = deck[code[x][i]];
            memcpy(deck, tmp_deck, sizeof(deck));
        }
        for (i = 1; i <= 52; ++i)
        {
            x = (deck[i] - 1) % 13;
            if (x < 9) printf("%d", x + 2);
            else printf("%s", value[x % 9]);
            printf(" of ");
            puts(suit[(deck[i] - 1) / 13]);
        }
        if (T) putchar(10);
    }
    return 0;
}

作者:csdn博客 synapse7

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索card
, line
, shuffle
, of
, by
The
stack up、tolerance stack up、stack up against、pcb stack up、叠层 stack up,以便于您获取更多的相关知识。

时间: 2024-10-18 13:28:10

UVa 10205 Stack 'em Up (模拟)的相关文章

UVa 10194 Football (aka Soccer) (模拟)

10194 - Football (aka Soccer) Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=1135 The Problem Football the most popular sport in the world (americans ins

UVa 10114 Loansome Car Buyer (模拟)

10114 - Loansome Car Buyer Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1055 Kara Van and Lee Sabre are lonesome. A few months ago they took out a loan

UVa 489 Hangman Judge:模拟&amp;amp;字符串匹配

489 - Hangman Judge Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430 In ``Hangman Judge,'' you are to write a program that judges a series of Hangman g

算法题:UVa 591 Box of Bricks (模拟)

591 - Box of Bricks Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=53 2 Little Bob likes playing with his box of bricks. He puts the bricks one upon an

uva 540 Team Queue

点击打开链接uva 540 思路: list+map模拟 分析: 1 题目的意思是有n个队伍,每个队伍的人数为m. 2 现在有三种操作,ENQUEUE x是插入x,如果队列里面已经有x这一队的成员那么直接插入到这一队的最后一个,否则插入到队列的最后一个:DEQUEUE 是直接拿到队列的第一个元素输出,并删除队列的第一个元素:STOP是停止 3 直接利用map和list来模拟,由于题目要求要插入的具体的位置所以用list来模拟 代码: #include<map> #include<list

PHP常用算法和数据结构示例(必看篇)

实例如下: </pre><pre name="code" class="php"><?php /** * Created by PhpStorm. * User: qishou * Date: 15-8-2 * Time: 上午9:12 */ header("content-type:text/html;charset=utf-8"); $arr = array(3,5,8,4,9,6,1,7,2); echo im

UVa 550 Multiplying by Rotation:模拟乘法

550 - Multiplying by Rotation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=491 Warning: Not all numbers in this problem are decimal numbers! Multiplic

UVa 101 The Blocks Problem (超级模拟)

101 - The Blocks Problem Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=37 Background Many areas of Computer Science use simple, abstract domains for bot

UVa 11210 Chinese Mahjong :模拟&amp;amp;枚举&amp;amp;回溯

11210 - Chinese Mahjong Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2151 Mahjong () is a game of Chinese origin usually played by four persons with tiles resembling dominoes and beari