You are given N cards. Each card consists of a suit and a rank. There are four suits, S…
- User
You are given N cards. Each card consists of a suit and a rank. There are four suits, S (Spades), H (Hearts), D (Diamonds) and C (Clubs), and thirteen ranks, ordered (from the lowest to the highest) 2, 3, 4, 5, 6, 7, 8, 9, 10, J (Jack), Q (Queen), K (King) and A (Ace).
Each card is represented by a string in the format "". For example, 10 of Spades is described as "105", and Queen of Hearts as "QH".
There are six ranked card sets (described in detail below). Sets are ordered by their strength from the weakest to the strongest. Your task is to detect the card sets that can be formed from the given cards. Detecting each card set is scored separately and is worth an equal number of points. If you detect more than one set, select the strongest one.
Write a function:
Results solution(vector &cards);
that, given an array of strings cards, returns a Results object representing the strongest card set that can be formed.
Assume that the following declarations are given:
struct Results { string set_name; vector selected_cards; };
set_name is a string which should be the name of detected set (see below);
selected_cards is a list of strings, which should be made of cards that form the detected set. Cards can be listed in any order. Card sets:
There are six card sets ordered by their strength from the weakest (single card) to the strongest (a triple and a pair).
Set 1: single card
Name: "single card"
Description: A single card of the highest rank; the suit does not matter.
For example, for cards = ['2H", "4H", "7C", "90", "100", "KS", your function should return:
{ "set_name" = "single card", "selected_cards" = ["KS"]}
Set 2: pair
Name: "pair"
Description: Two cards sharing the same rank; suits do not matter. If there are multiple pairs, return any one with the highest rank.
For example, for cards = ['AS", "10H", "8H", "105", "80"), one of the correct results is:
{ "set_name"= "pair", "selected_cards" ["10H", "105"]}
Set 3: triple
-
Name: "triple"
-
Description: Three cards sharing the same rank; suits do not matter. If there are multiple ways to choose a triple, return any with the highest rank.
For example, for cards = ["AS", "JS", "AH", "AD", "100", "AC"], one of the correct results is:
{ "set_name" = "triple", "selected_cards" = "AH", "AD", "AC"]
}
Set 4: five in a row
Name: "five in a row"
Description: Five cards of consecutive ranks starting with the highest possible rank; suits do not matter. If there are multiple ways to choose five such cards, return any.
-
- Assistant