Card Repetitions Z61488


Statement
 

pdf   zip

thehtml

Write a program to report the consecutive repetitions in a sequence of Poker cards. The goal is to detect consecutive subsequences of identical cards, of length k ≥ 2, and write to the output a phrase describing each subsequence using the typical Poker names. We will consider 4 cases: "Pair" (k = 2), "Trio" (k = 3), "Poker" (k = 4), and longer repetitions (k > 4). If a card does not appear repeated in the sequence, nothing needs to be written. There’s no need to consider overlapping, only the longest consecutive subsequences have to be reported.

Input

The input consists of a sequence of characters representing the cards. As in the problem "Better Card", the characters for the cards are A, 2, 3, ..., 9, 0, J, Q, and K. The sequence of cards ends with a period, i.e., the character '.', and it can be empty.

Output

You must detect the consecutive repetitions of cards and write to the output the description corresponding to the number of times k that the card C has been repeated: "Pair of Cs", "Trio of Cs", "Poker of Cs" or "k Cs!". Each description should be on a different line and in the order in which they appear in the input sequence. Refer to the public test cases for concrete examples.

Observation

In this problem, the input must be processed character by character; if you use strings or any method to store the card sequence, the problem will be considered invalid. Also, note that the sequence is supposed to come from an unlimited source of cards, so no maximum length can be assumed.

Public test cases
  • Input

    11.

    Output

    Pair of 1s
    
  • Input

    JJJ8A.

    Output

    Trio of Js
    
  • Input

    122333KKKK9.

    Output

    Pair of 2s
    Trio of 3s
    Poker of Ks
    
  • Input

    1AAAAA5QQQQQQQQ7.

    Output

    5 As!
    8 Qs!
    
  • Information
    Author
    PRO1
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++