CCC '01 S1 - Keeping Score

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 16M

Problem type

Canadian Computing Competition: 2001 Stage 1, Junior #3, Senior #1

In a card game, each player's hand is made up of 13 cards. Each hand has a total point value determined by the number of cards that have a point value. The cards which are worth points are the Ace (4 points), King (3 points), Queen (2 points) and Jack (1 point). The other cards (2, 3, 4, 5, 6, 7, 8, 9, 10) have no point value.

There are four of each type of card, one in each of the four suits. The suits are called clubs (C), diamonds (D), hearts (H), and spades (S). As well, points are assigned for each suit which has a void (3 points), a singleton (2 points), or a doubleton (1 point). A void in a suit means that there are no cards of that suit (e.g. a hand with no spades). A singleton in a suit means that there is only one card in that suit (e.g. a hand with only one diamond). A doubleton in a suit means that there are only two cards in that suit.

Write a program to read a set of thirteen cards in the form of a string, then evaluate the number of points in the hand. The suits will appear in increasing alphabetical order. Within each suit there will be no duplicate cards.

The output is to be the hand and the point value shown in a table form as below. Your output should list the cards in the same order as the input. Note that 10 is represented by the character T in both the input and the output.

Sample Input 1


Sample Output 1

Cards Dealt              Points
Clubs 2 5 8 T J K             4
Diamonds 6 9 Q A              6
Hearts                        3
Spades T J A                  5
                       Total 18

Sample Input 2


Sample Output 2

Cards Dealt              Points
Clubs A                       6
Diamonds 5 7 8 K A            7
Hearts A                      6
Spades 4 7 T Q K A            9
                       Total 28

Note: your output does not need to match exactly. The spacing is up to you.


  • -1
    daniel_xu  commented on Jan. 9, 2018, 7:56 p.m.


    Please Help I don't understand where I went wrong

    • 1
      11238  commented on Jan. 9, 2018, 9:55 p.m.

      Compare your last line of output(The "Total Points" one) to the sample Output, you will know the reason xD

  • 0
    Selena_Liu  commented on June 26, 2017, 9:59 p.m.

    only 2 out of 4 tests are succeeding... I don't know what's wrong

    • 0
      Pleedoh  commented on June 29, 2017, 6:38 p.m.

      Your code seems over complicated, just process the string letter by letter,printing out the cards and tracking points. When you encounter a new suit, as in a "D","H", or "S", print out the info you've been holding, wipe your variables, and keep going, this time on another suit.

  • -1
    susheelk  commented on Feb. 12, 2017, 7:14 p.m.

    WA Can someone take a loot at my submission? It seems right but the spacing seems to be off

    • 1
      Kirito  commented on Feb. 12, 2017, 8:16 p.m.

      You are printing pts[0] for each suit.

  • -5
    Centurion902  commented on Feb. 10, 2017, 8:31 p.m. edit 2

    Silly mistake

  • -3
    jpr4  commented on Jan. 5, 2017, 12:12 p.m.

    Can anyone look into my submissions? It seems correct.

    • 0
      Kirito  commented on Jan. 5, 2017, 1:31 p.m. edited

      The cards should be space separated.

      E.g. Diamonds 5 7 8 K A

      You also misspelled Clubs

      • -2
        jpr4  commented on Jan. 6, 2017, 11:41 a.m.


  • -2
    root  commented on Nov. 3, 2016, 4:25 p.m.

    My submission segfaults on problem one before even reaching main?

    • 0
      Kirito  commented on Nov. 3, 2016, 6:58 p.m.

      Declare a larger buffer, 4096 is a commonly used number.