For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
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 "<rank><suit>". For example, 10 of Spades is described as "10S", 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<string> &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<string> 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.Set 1: Single Card
Set 2: Pair
Example for Set 2:
{
"set_name": "pair",
"selected_cards": ["10H", "10S"]
}
Set 3: Triple
Example for Set 3:
{
"set_name": "triple",
"selected_cards": ["AH", "AD", "AC"]
}
Set 4: Five in a Row
Example for Set 4:
{
"set_name": "five in a row",
"selected_cards": ["7S", "8S", "9S", "10S", "JC"]
}
Set 5: Suit
Example for Set 5:
{
"set_name": "suit",
"selected_cards": ["2D", "4D", "6D", "8D", "9D"]
}
Set 6: A Triple and a Pair
Example for Set 6:
{
"set_name": "a triple and a pair",
"selected_cards": ["10D", "10H", "10C", "JH", "JC"]
}
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 "<rank><suit>". For example, 10 of Spades is described as "10S", 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<string> &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<string> 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.Set 1: Single Card
Set 2: Pair
Example for Set 2:
{
"set_name": "pair",
"selected_cards": ["10H", "10S"]
}
Set 3: Triple
Example for Set 3:
{
"set_name": "triple",
"selected_cards": ["AH", "AD", "AC"]
}
Set 4: Five in a Row
Example for Set 4:
{
"set_name": "five in a row",
"selected_cards": ["7S", "8S", "9S", "10S", "JC"]
}
Set 5: Suit
Example for Set 5:
{
"set_name": "suit",
"selected_cards": ["2D", "4D", "6D", "8D", "9D"]
}
Set 6: A Triple and a Pair
Example for Set 6:
{
"set_name": "a triple and a pair",
"selected_cards": ["10D", "10H", "10C", "JH", "JC"]
}
Output