Skip to content

Commit e3d81fe

Browse files
committed
srm 206 div 1 250
1 parent 3f4207f commit e3d81fe

File tree

4 files changed

+152
-139
lines changed

4 files changed

+152
-139
lines changed

HexagonIntersections.cpp

-58
This file was deleted.

HexagonIntersections.txt

-81
This file was deleted.

OmahaLow.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <iostream>
2+
#include <sstream>
3+
#include <vector>
4+
#include <algorithm>
5+
#include <set>
6+
#include <map>
7+
#include <queue>
8+
#include <cstring>
9+
#include <climits>
10+
using namespace std;
11+
12+
class OmahaLow {
13+
public:
14+
string low(string sharedCards, string playersCards)
15+
{
16+
set<int> A, B;
17+
for(char c : sharedCards)
18+
if(c <= '8') A.insert(c);
19+
for(char c : playersCards)
20+
if(c <= '8') B.insert(c);
21+
22+
for(int i1 : A)
23+
for(int i2 : A)
24+
for(int i3 : A)
25+
for(int i4 : B)
26+
for(int i5 : B)
27+
{
28+
set<char> T;
29+
T.insert(i1);T.insert(i2);T.insert(i3);T.insert(i4);T.insert(i5);
30+
if(T.size() == 5){
31+
32+
string r;
33+
for(char c : T) r.push_back(c);
34+
sort(r.rbegin(), r.rend());
35+
return r;
36+
}
37+
}
38+
return "";
39+
}
40+
41+
// BEGIN CUT HERE
42+
public:
43+
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); }
44+
private:
45+
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
46+
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
47+
void test_case_0() { string Arg0 = "123QK"; string Arg1 = "45TJ"; string Arg2 = "54321"; verify_case(0, Arg2, low(Arg0, Arg1)); }
48+
void test_case_1() { string Arg0 = "55443"; string Arg1 = "2345"; string Arg2 = ""; verify_case(1, Arg2, low(Arg0, Arg1)); }
49+
void test_case_2() { string Arg0 = "1357Q"; string Arg1 = "345J"; string Arg2 = "75431"; verify_case(2, Arg2, low(Arg0, Arg1)); }
50+
void test_case_3() { string Arg0 = "76285"; string Arg1 = "4816"; string Arg2 = "65421"; verify_case(3, Arg2, low(Arg0, Arg1)); }
51+
void test_case_4() { string Arg0 = "12345"; string Arg1 = "3339"; string Arg2 = ""; verify_case(4, Arg2, low(Arg0, Arg1)); }
52+
void test_case_5() { string Arg0 = "58463"; string Arg1 = "947K"; string Arg2 = "76543"; verify_case(5, Arg2, low(Arg0, Arg1)); }
53+
void test_case_6() { string Arg0 = "67521"; string Arg1 = "J859"; string Arg2 = "86521"; verify_case(6, Arg2, low(Arg0, Arg1)); }
54+
55+
// END CUT HERE
56+
57+
};
58+
59+
// BEGIN CUT HERE
60+
int main(){
61+
62+
OmahaLow ___test;
63+
___test.run_test(-1);
64+
65+
}
66+
// END CUT HERE

OmahaLow.txt

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
PROBLEM STATEMENT
2+
3+
"Omaha" is a variation of poker in which half of the pot goes to the player(s) with the lowest hand. The game is played with a deck of cards, each with a value between 1 through 13, inclusive. Each player is dealt 4 cards, and then 5 shared cards are dealt face up in the center of the table. Each player makes their lowest possible five-card hand by selecting exactly two of their own cards and exactly three of the shared cards.
4+
5+
6+
In order for a hand to qualify, all five cards must have a value of 8 or lower, and all five cards must have different values. If a player cannot form such a hand, he/she is not eligible to win this half of the pot.
7+
8+
9+
Two low hands are compared by sorting the cards from highest to lowest. Starting from the highest card in each hand, compare corresponding cards in each hand until you find the first two with different values. The hand with the smaller of these two cards is the lower hand, and therefore the winner.
10+
For example, "76521" is lower than "86432", because 7 is less than 8. "75421" is lower than "75431" because 2 is less than 3.
11+
If both hands have the same five cards, they get an equal share of this half of the pot.
12+
13+
14+
You will be given the five shared cards, and the 4 cards held by one player.
15+
The cards will be given as strings, with each character in each string representing one card.
16+
Characters '1' through '9' represent cards of values 1 through 9, 'T' is 10, 'J' is 11, 'Q' is 12, and 'K' is 13.
17+
Return a string of 5 characters, representing the 5 cards in this player's lowest hand (as defined above).
18+
The cards should be sorted highest to lowest. If the player does not have a qualifying low hand, return an empty string.
19+
20+
21+
NOTE: Ignore anything else you may know about cards and card games. For example, suits are not used to determine low hands, and are not considered in this problem. The cards of value 1 are also known as "aces", but we'll just call them '1' for this problem. Also, a standard deck of cards has 4 cards of each value, but this will not be enforced in the input.
22+
23+
24+
DEFINITION
25+
Class:OmahaLow
26+
Method:low
27+
Parameters:string, string
28+
Returns:string
29+
Method signature:string low(string sharedCards, string playersCards)
30+
31+
32+
CONSTRAINTS
33+
-sharedCards will contain exactly 5 characters.
34+
-playersCards will contain exactly 4 characters.
35+
-All charaters in sharedCards and playersCards will be one of "123456789TJQK".
36+
37+
38+
EXAMPLES
39+
40+
0)
41+
"123QK"
42+
"45TJ"
43+
44+
Returns: "54321"
45+
46+
The lowest possible hand is "54321", and the player can make that hand by selecting the 1, 2, and 3 from the shared cards, and the 4 and 5 from the player's cards.
47+
48+
1)
49+
"55443"
50+
"2345"
51+
52+
Returns: ""
53+
54+
There are only 4 unique cards in all (2, 3, 4, and 5), so it is impossible to form a low hand with 5 unique cards.
55+
56+
2)
57+
"1357Q"
58+
"345J"
59+
60+
Returns: "75431"
61+
62+
There are two ways to make the hand "75431": "731" and "54", or "751" and "43".
63+
64+
3)
65+
"76285"
66+
"4816"
67+
68+
Returns: "65421"
69+
70+
4)
71+
"12345"
72+
"3339"
73+
74+
Returns: ""
75+
76+
5)
77+
"58463"
78+
"947K"
79+
80+
Returns: "76543"
81+
82+
6)
83+
"67521"
84+
"J859"
85+
86+
Returns: "86521"

0 commit comments

Comments
 (0)