UVa 10205 Stack ' em Up (analog)

Source: Internet
Author: User
Tags printf shuffle time limit

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 cards, and values in each of four suits. The values are Named2, 3, 4, 5, 6, 7, 8, 9, ten, Jack, Queen, King, Ace. The suits are named clubs, diamonds, Hearts, spades. A particular card in the deck can is 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 the-i-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" same way it is whenever. A very simple example are the "bottom card" shuffle which removes the bottom card and places it in the top. By using various combinations of this known shuffles, the crooked dealer can arrange to stack the cards in just about any particular order.

You are have been retained by the security Manager to track this dealer. You are are given a list of all the shuffles performed by the dealer, along with visual cues, and allow to determine 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 in a line by itself indicating the number of cases following, each of them as described below. This are followed by a blank line, and there are also a blank line between two consecutive.

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

Several lines follow; Each containing a integer k between 1 and n indicating that you have observed the dealer applying the kth shuffle I n the input.

Output

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

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

Sample Input

1

2
2 1 3 4 5 6-7 8 9 27 28 29 30 31 32 33 34 A; 35 A-M
9 (a)
2 3 4 5 6 7 8 (9), 27 (+) (k) (k) (k)
The 1
1 2 in a-m at the same------

Output for Sample Input

See more highlights of this column: 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 Diam Onds
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< C27/>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 to
Sp Ades
Jack of Spades
Queen of Spades
Ace of Spades
3 of Clubs

Direct simulation.

Complete code:

/*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 <= ++j) scanf ("%d", &code[i][j));  
        GetChar ();  
        for (i = 1; I <= ++i) deck[i] = i;  
            while (gets (s) && s[0]) {sscanf (S, "%d", &x);  
            for (i = 1; I <= ++i) tmp_deck[i] = deck[code[x][i]];  
        memcpy (deck, Tmp_deck, sizeof (deck));  
            for (i = 1; I <= ++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; }

Author: csdn Blog Synapse7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.