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

[UVA] 11225 - Tarot scores

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

G. Tarot scores

Time limit: 1s

A hand in the game of
tarot

Tarot is a card game played in France. It is played with a 78-card deck, composed with 21 trump cards (named one, two, ..., twenty-one), a special card (named the fool) and four suits (spades, hearts, diamonds, clubs). Each suit has fourteen cards: ten pip cards (ace, two, ..., ten), and four face cards: jack, knight, queen and king.

Three cards have a special status. They are called the oudlers and are the fool, the 1 of trumps and the 21 of trumps.

The game is composed of a bidding phase, followed by a main phase. The bidding phase consists in choosing one of the players as the "taker". In the main phase, the players play tricks and try to win as many cards as possible. The outcome of a game is determined by the number of points won by the taker, which is the sum of the values of the cards won by the taker. The value that the taker needs to achieve depends on the number of oudlers he has won throughout the game:

  • 3 oudlers: 36 points,
  • 2 oudlers: 41 points,
  • 1 oudlers: 51 points,
  • no oudlers: 56 points,

The value of each card is as follows:

  • kings and oudlers: 4½ points,
  • queens: 3½ points,
  • knights: 2½ points,
  • jacks: 1½ points,
  • all other cards: ½ point.

For instance, imagine that, at the end of the game, the taker has won the following four cards: ace of spades, eight of diamonds, fool and twenty-one of trumps. Two of these cards are oudlers, so the number of points that the taker needs to score to win is 41. However the sum of the points earned is only 10, and the taker has lost, since the total is 31 points short of the required total.

You have to write a program that, given the list of cards won by the taker, indicates if the taker has won her bid, and the number of points she has in excess, or lost and the number of missing points.

Input

The first line of input gives the number of cases, T (1 ≤ T ≤ 100). T test cases follow. Each one contains an even integer M (0 ≤ M ≤ 78), representing the number of cards won by the taker. Then M lines follow each with a string representing a card (see sample input).

Output

For each test case, output the score. The score of the n-th game starts with the header Game #n, on a line of its own, followed by the result (see sample output for the exact syntax), also one a line of its own. The scores are separated by blank lines

Sample input

2
4
ace of spades
eight of diamonds
fool
twenty-one of trumps
42
ace of diamonds
ace of hearts
eight of clubs
eight of diamonds
eight of spades
eight of trumps
eleven of trumps
five of clubs
five of diamonds
four of clubs
four of spades
four of trumps
fourteen of trumps
jack of clubs
jack of hearts
jack of spades
king of clubs
king of hearts
knight of clubs
knight of diamonds
knight of hearts
nine of diamonds
nineteen of trumps
one of trumps
queen of clubs
queen of diamonds
queen of spades
seven of spades
seven of trumps
six of clubs
six of hearts
six of trumps
sixteen of trumps
ten of clubs
ten of diamonds
three of clubs
three of diamonds
three of hearts
three of spades
three of trumps
two of diamonds
two of spades

Sample output

Hand #1
Game lost by 31 point(s).

Hand #2
Game won by 0 point(s).

Problem setter: David Deharbe.
Universidade Federal do Rio Grande do Norte Qualifying Contest IV, June 9th, 2007.

這款法國遊戲,不是很懂遊戲的步驟,不過按照他喊的指定個數後,
要贏的目標點數就會減少,問最後得到的點數與目標點數差多少。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    int testcase, n, cases = 0;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d", &n);
        while(getchar() != '\n');
        int oudler = 0;
        int pt = 0, hpt = 0, i;
        char s[105], ss[105];
        for(i = 0; i < n; i++) {
            gets(s);
            hpt++;
            if(!strcmp(s, "fool") || !strcmp(s, "twenty-one of trumps") ||
               !strcmp(s, "one of trumps")) {
                oudler++;
                pt += 4;
            } else {
                sscanf(s, "%s", ss);
                if(!strcmp(ss, "jack"))
                    pt += 1;
                else if(!strcmp(ss, "knight"))
                    pt += 2;
                else if(!strcmp(ss, "queen"))
                    pt += 3;
                else if(!strcmp(ss, "king"))
                    pt += 4;
            }
        }
        int goal;
        if(oudler == 0) goal = 56;
        if(oudler == 1) goal = 51;
        if(oudler == 2) goal = 41;
        if(oudler == 3) goal = 36;
        pt += hpt/2;
        printf("Hand #%d\n", ++cases);
        if(pt >= goal)
            printf("Game won by %d point(s).\n", pt-goal);
        else
            printf("Game lost by %d point(s).\n", goal-pt);
        if(testcase)    puts("");
    }
    return 0;
}

台長: Morris
人氣(1,139) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][模擬] 339 - SameGame Simulation
此分類上一篇:[UVA] 162 - Beggar My Neighbour

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