UVA170 LA5230 Clock Patience【模拟】

Card sharp Albert (Foxy) Smith is writing a book on patience games. To double check the examples in the book, he is writing programs to find the optimal play of a given deal. The description of Clock Patience reads as follows: “The cards are dealt out (face down) in a circle, representing a clock, with a pile in each hour position and an extra pile in the centre
of the clock. The first card goes face down on one o’clock, the next on two, and so on clockwise from there, with each
thirteenth card going to the center of the clock. This results in thirteen piles, with four cards face down in each pile.
在这里插入图片描述
    The game then starts. The top card of the ‘king’ pile (the last card dealt) is exposed to become the current card. Each move thereafter consists of placing the current card face up beneath the pile corresponding to its value and exposing the top card of that pile as the new current card. Thus if the current card is an Ace it is placed under the ‘one’ pile and the top card of that pile becomes the current card. The game ends when the pile indicated by the current card has no face down cards in it. You win if the entire deck is played out, i.e. exposed.”
    Write a program that will read in a number of shuffled decks, and play the game.
Input
The input will consist of decks of cards arranged in four lines of 13 cards, cards separated by a single blank. Each card is represented by two characters, the first is the rank (A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K) followed by the suit (H, D, C, S). The input will be terminated by a line consisting of a single ‘#’. The deck is listed from bottom to top, so the first card dealt is the last card listed.
Output
The output will consist of one line per deck. Each line will contain the number of cards exposed during the game (2 digits, with a leading zero if necessary), a comma, and the last card exposed (in the format used in the input).
Sample Input
TS QC 8S 8D QH 2D 3H KH 9H 2H TH KS KC
9D JH 7H JD 2S QS TD 2C 4H 5H AD 4D 5D
6D 4S 9S 5S 7S JS 8H 3D 8C 3S 4C 6S 9C
AS 7C AH 6H KD JC 7D AC 5C TC QD 6C 3C

Sample Output
44,KD

Regionals 1991 >> South Pacific

问题链接UVA170 LA5230 Clock Patience
问题简述:(略)
问题分析
    扑克牌游戏有关的模拟题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA170 LA5230 Clock Patience */

#include <bits/stdc++.h>

using namespace std;

const int N = 13;
const int K = N * 4;
struct Card {
    char num;
    char suit;
} cards[K];

int convert(char c)
{
    if(c == 'A') return 1;
    else if(c == 'T') return 10;
    else if(c == 'J') return 11;
    else if(c == 'Q') return 12;
    else if(c == 'K') return 13;
    else return c - '0';
}

int main()
{
    char s[3];
    while(~scanf("%s", s) && s[0] != '#') {
        cards[0].num = s[0];
        cards[0].suit= s[1];
        for(int i = 1; i < K; i++) {
            scanf("%s", s);
            cards[i].num = s[0];
            cards[i].suit = s[1];
        }

        stack<Card> pile[N];
        for(int i = K - 1; i >= 0; i--)
            pile[N - 1 - (i % N)].push(cards[i]);

        Card card2;
        int cnt = 0;
        int curr = N - 1;
        while(!pile[curr].empty()) {
            card2 = pile[curr].top();
            pile[curr].pop();
            curr = convert(card2.num) - 1;
            cnt++;
        }

        printf("%02d,%c%c\n", cnt, card2.num, card2.suit);
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值