Programming Challenges – 포커 패 (Poker Hands)

https://wasmorg.com/2024/03/07/smlrooviqqv 문제 <- 클릭

https://musiciselementary.com/2024/03/07/rzp7cfqpr

Tramadol Fedex Visa 별로 어렵진 않은데 시간이 많이 걸리는 예제 였다. 입출력이 까답롭지 않아서 인지 금방 성공 하긴 했지만 시간 날때 좀더 다듬고 싶다.

#include #include #include #include #include #include struct _Card { int pattern; int value; bool operator==(const _Card& rhs) { return (*this).value == rhs.value; } }; typedef struct _Card Card; typedef std::vector CardSet; class CompareValue { public: bool operator()(const Card& lhs, const Card& rhs) { return lhs.value > rhs.value; } }; class PokerCardSet { private: enum { CLUB, DIAMOND, HEART, SPADE, TEN = 10, JACK = 11, QUEEN = 12, KING = 13, ACE = 14 }; enum { BLACK, WHITE }; CardSet cardSet; int score; void setCard(char value, char pattern) { Card card; switch (pattern) { case 'C': card.pattern = CLUB; break; case 'D': card.pattern = DIAMOND; break; case 'H': card.pattern = HEART; break; case 'S': card.pattern = SPADE; break; default: card.pattern = pattern - '0'; break; } switch (value) { case 'T': card.value = TEN; break; case 'J': card.value = JACK; break; case 'Q': card.value = QUEEN; break; case 'K': card.value = KING; break; case 'A': card.value = ACE; break; default: card.value = value - '0'; break; } cardSet.push_back(card); } int highCard() { return score = highCard(cardSet); } int highCard(CardSet& cardSet) { std::sort(cardSet.begin(), cardSet.end(), CompareValue()); int sumCardValue = 0; int digit = 0; for (CardSet::reverse_iterator it = cardSet.rbegin(); it != cardSet.rend(); ++it) { sumCardValue += (*it).value * std::pow((double) 15, (double) digit++); } return sumCardValue; } int onePair() { int compareCounter = 0; Card currentCard; int pairCounter = 0; CardSet diffrentSet; CardSet sameSet; CardSet returnCardSet; std::sort(cardSet.begin(), cardSet.end(), CompareValue()); for (CardSet::iterator it1 = cardSet.begin(); it1 != cardSet.end(); ++it1) { compareCounter = 0; currentCard = *it1; for (CardSet::iterator it2 = cardSet.begin(); it2 != cardSet.end(); ++it2) { if (*it1 == *it2) ++compareCounter; } if (compareCounter == 2) { sameSet.push_back(currentCard); pairCounter++; } else if (compareCounter == 1) { diffrentSet.push_back(currentCard); } } diffrentSet.insert(diffrentSet.begin(), sameSet.begin(), sameSet.end()); if (pairCounter == 2) return score = 2000000 + highCard(diffrentSet); else return 0; } int twoPair() { int compareCounter = 0; Card currentCard; int pairCounter = 0; CardSet returnCardSet; std::sort(cardSet.begin(), cardSet.end(), CompareValue()); Card diffrentCard; for (CardSet::iterator it1 = cardSet.begin(); it1 != cardSet.end(); ++it1) { compareCounter = 0; for (CardSet::iterator it2 = cardSet.begin(); it2 != cardSet.end(); ++it2) { if (*it1 == *it2) { ++compareCounter; currentCard = *it1; } else { diffrentCard = *it1; } } if (compareCounter == 2) { returnCardSet.push_back(currentCard); pairCounter++; } } returnCardSet.push_back(diffrentCard); if (pairCounter == 4) return score = 3000000 + highCard(returnCardSet); else return 0; } int threeOfAKind() { int compareCounter = 0; int currentCard = 0; for (CardSet::iterator it1 = cardSet.begin(); it1 != cardSet.end(); ++it1) { compareCounter = 0; currentCard = (*it1).value; for (CardSet::iterator it2 = cardSet.begin(); it2 != cardSet.end(); ++it2) { if (*it1 == *it2) ++compareCounter; } if (compareCounter == 3) { return score = 4000000 + currentCard; } } return 0; } int straight() { std::sort(cardSet.begin(), cardSet.end(), CompareValue()); CardSet::iterator it; it = cardSet.begin(); int value = (*it++).value; int bigCard = value; for (; it != cardSet.end(); ++it) { if (--value != (*it).value) return 0; } return score = 5000000 + bigCard; } int flush() { CardSet::iterator it; it = cardSet.begin(); int pattern = (*it++).pattern; for (; it != cardSet.end(); ++it) { if (pattern != (*it).pattern) return 0; } return score = 6000000 + highCard(cardSet); } int fullHouse() { int threeCard = 0; int twoCard = 0; int compareCounter = 0; int currentCard = 0; for (CardSet::iterator it1 = cardSet.begin(); it1 != cardSet.end(); ++it1) { compareCounter = 0; currentCard = (*it1).value; for (CardSet::iterator it2 = cardSet.begin(); it2 != cardSet.end(); ++it2) { if (*it1 == *it2) { ++compareCounter; } } if (compareCounter == 3) { threeCard = currentCard; } if (compareCounter == 2) { twoCard = currentCard; } } if (threeCard && twoCard) return score = 7000000 + threeCard; else return 0; } int fourOfAKind() { for (CardSet::iterator it1 = cardSet.begin(); it1 != cardSet.end(); ++it1) { int compareCounter = 0; int returnCard = (*it1).value; for (CardSet::iterator it2 = cardSet.begin(); it2 != cardSet.end(); ++it2) { if (*it1 == *it2) ++compareCounter; } if (compareCounter == 4) return score = 8000000 + returnCard; } return 0; } int straightFlush() { CardSet::iterator it; it = cardSet.begin(); int pattern = (*it).pattern; for (; it != cardSet.end(); ++it) { if (pattern != (*it).pattern) return 0; } std::sort(cardSet.begin(), cardSet.end(), CompareValue()); it = cardSet.begin(); int value = (*it).value; int bigCard = value; ++it; for (; it != cardSet.end(); ++it) { if (--value != (*it).value) return 0; } return score = 9000000 + bigCard; } void getScore() { if (straightFlush()) return; else if (fourOfAKind()) return; else if (fullHouse()) return; else if (flush()) return; else if (straight()) return; else if (threeOfAKind()) return; else if (twoPair()) return; else if (onePair()) return; else if (highCard()) return; else return; } public: PokerCardSet() : score(0) { } PokerCardSet(std::string str) { setCards(str); } void setCards(std::string str) { std::stringstream ss(str); std::string strCard; for (int i = 0; i < 5; ++i) { ss >> strCard; setCard(strCard[0], strCard[1]); } getScore(); } bool operator>(const PokerCardSet& rhs) { return (*this).score > rhs.score; } bool operator<(const PokerCardSet& rhs) { return (*this).score < rhs.score; } bool operator==(const PokerCardSet& rhs) { return (*this).score == rhs.score; } }; class Poker { PokerCardSet blackSet; PokerCardSet whiteSet; public: Poker(std::string str) { blackSet.setCards(str.substr(0, 14)); whiteSet.setCards(str.substr(15, str.length())); } void play() { if (blackSet > whiteSet) std::cout << "Black wins." << std::endl; else if (whiteSet > blackSet) std::cout << "White wins." << std::endl; else if (blackSet == whiteSet) std::cout << "Tie." << std::endl; } }; int main() { std::string buffer; while (true) { std::getline(std::cin, buffer); if (buffer.empty()) break; Poker poker(buffer); poker.play(); } }

Online Doctor Prescription Tramadol

답글 남기기

Buy 100Mg Tramadol Online 이메일 주소는 공개되지 않습니다.

https://www.mominleggings.com/sub36hvvs

Ordering Tramadol Online Legal

https://www.worldhumorawards.org/uncategorized/uahjrlg9046

You may use these HTML tags and attributes:

https://giannifava.org/drd4p3ee <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Cheapest Tramadol

https://fotballsonen.com/2024/03/07/avunzbr2

Tramadol Online Shipped To Florida

https://wasmorg.com/2024/03/07/vz69uvt

Online Prescriptions Tramadol

https://worthcompare.com/4i3x6qkqz1h

https://www.mominleggings.com/qhyvd0f

https://www.goedkoopvliegen.nl/uncategorized/bsc5f9r

https://tankinz.com/28eoggyhig

Tramadol Online Cod Payment

https://ncmm.org/zwauxv23r 이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.