24h購物| | PChome| 登入
2013-08-11 10:11:01| 人氣1,791| 回應0 | 上一篇 | 下一篇

[UVA] 10646 - What is the Card

推薦 0 收藏 0 轉貼0 訂閱站台

What is the Card?

Input: standard input
Output: standard output
Time Limit: 1 second


    Kowshik and Tafsir are two brilliant students of Chittagong College, the best college for a century at Chittagong in Bangladesh. Their days begin with lots of classes and soon they become loaded. That is why, to give their brains rest, they like to play a card game "What is the card?" when they get free time between the classes. The game is described below:

    In this game, the value of a card is defined as the value of the card face if the card face shows a number between 2 and 9, otherwise the value is 10. Initially there is a pile consisting of 52 cards with card faces down. Take the top 25 cards of the pile in the hand. Set Y = 0. Then execute three times the following steps together:

  • Take the top card of the cards of the pile and determine its value.

  • Let the card value be X. Add X to Y.

  • Put this card and the top (10-X) cards of the pile away.

At last put the 25 remaining cards in your hand on top of the pile. The task is to determine the Yth card from the pile, counted from the bottom.

Tafsir and Kowshik know the initial order of the cards, so they think they can tell the Yth card without looking in the pile, but they fail to detect the right card most of the time and think themselves to be dull. Please help them to increase their self-confidence.

 

Input

 

The first line in the input file contains an integer representing the number of test cases. Each of the test cases follows below. Each case consists of 52 cards given in the order of the initial pile, from bottom to top. The format for each card is a string with 2 characters, first character is the value, second character is the suit.

Output

 

For each test case, first print the serial number of the case and then print the target card separated by an space from the serial number. Check the sample input & output. You are guaranteed that there is always a solution.

 

Sample Input

2

AC KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C AD KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AH KH QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AS KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S

AC KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C AD KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AH KH QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AS KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S


Sample Output

Case 1: 8H

Case 2: 8H



題目描述:

盤面上有 52 張牌疊再一起,先將上方 25 張牌移到手上。

剩餘 27 張牌,依序打開 3 張,對於每一次打開時,假設點數為 X, 則先抽走 10-X 張,
而 3 次點數 X 總和為 Y。

將原本 25 張牌疊回去,問從底部算起第 Y 張牌是什麼。

#include <stdio.h>
int trans(char c) {
    if(c >= '0' && c <= '9')
        return c-'0';
    return 10;
}
int main() {
    int testcase;
    int i, j, cases = 0;
    scanf("%d", &testcase);
    while(testcase--) {
        char card[52][3];
        int pile[52];
        for(i = 0; i < 52; i++) {
            scanf("%s", card[i]);
            pile[i] = trans(card[i][0]);
        }
        int X, Y = 0, idx = 26;
        for(i = 0; i < 3; i++) {
            X = pile[idx--];
            Y += X;
            idx -= 10-X;
        }
        if(Y > idx)
            Y += (25-idx);
        printf("Case %d: %s\n", ++cases, card[Y]);
    }
    return 0;
}

台長: Morris
人氣(1,791) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA] 10284 - Chessboard in FEN
此分類上一篇:[UVA][日期] 12148 - Electricity

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文