The Psychic Poker Player |
In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at). The player may then discard between zero and five of his or her cards and have them replaced by the same number of cards from the top of the deck (which is face down). The object is to maximize the value of the final hand. The different values of hands in poker are given at the end of this problem.
Normally the player cannot see the cards in the deck and so must use probability to decide which cards to discard. In this problem, we imagine that the poker player is psychic and knows which cards are on top of the deck. Write a program which advises the player which cards to discard so as to maximize the value of the resulting hand.
Input will consist of a series of lines, each containing the initial five cards in the hand then the first five cards on top of the deck. Each card is represented as a two-character code. The first character is the face-value (A=Ace, 2-9, T=10, J=Jack, Q=Queen, K=King) and the second character is the suit (C=Clubs, D=Diamonds, H=Hearts, S=Spades). Cards will be separated by single spaces. Each input line will be from a single valid deck, that is there will be no duplicate cards in each hand and deck.
Each line of input should produce one line of output, consisting of the initial hand, the top five cards on the deck, and the best value of hand that is possible. Input is terminated by end of file.
Use the sample input and output as a guide. Note that the order of the cards in the player‘s hand is irrelevant, but the order of the cards in the deck is important because the discarded cards must be replaced from the top of the deck. Also note that examples of all types of hands appear in the sample output, with the hands shown in decreasing order of value.
TH JH QC QD QS QH KH AH 2S 6S 2H 2S 3H 3S 3C 2D 3D 6C 9C TH 2H 2S 3H 3S 3C 2D 9C 3D 6C TH 2H AD 5H AC 7H AH 6H 9H 4H 3C AC 2D 9C 3S KD 5S 4D KS AS 4C KS AH 2H 3C 4H KC 2C TC 2D AS AH 2C 9S AD 3C QH KS JS JD KD 6C 9C 8C 2D 7C 2H TC 4C 9S AH 3D 5S 2H QD TD 6S KH 9H AD QH
Hand: TH JH QC QD QS Deck: QH KH AH 2S 6S Best hand: straight-flush Hand: 2H 2S 3H 3S 3C Deck: 2D 3D 6C 9C TH Best hand: four-of-a-kind Hand: 2H 2S 3H 3S 3C Deck: 2D 9C 3D 6C TH Best hand: full-house Hand: 2H AD 5H AC 7H Deck: AH 6H 9H 4H 3C Best hand: flush Hand: AC 2D 9C 3S KD Deck: 5S 4D KS AS 4C Best hand: straight Hand: KS AH 2H 3C 4H Deck: KC 2C TC 2D AS Best hand: three-of-a-kind Hand: AH 2C 9S AD 3C Deck: QH KS JS JD KD Best hand: two-pairs Hand: 6C 9C 8C 2D 7C Deck: 2H TC 4C 9S AH Best hand: one-pair Hand: 3D 5S 2H QD TD Deck: 6S KH 9H AD QH Best hand: highest-card
1 | Royal Flush 同花大顺又称皇家同花顺 它是所有德州扑克中的王牌,即使您经常玩扑克,也很少见到这样的牌。好比打高尔夫球一杆进洞一样。它是由T(10)到Ace的清一色同花组成。 | |
| ||
2 | Straight Flush 同花顺 除了由最大同花所组成的同花大顺以外的同花组成的顺子。 | |
| ||
3 | Four-of-a-Kind 四条 四张同样的牌+任意一张牌 。 | |
| ||
4 | Full House 俘虏或船牌或葫芦 三条带一对,即三张同样的牌带两张同样的牌。如都是Full House,则先比较谁的三条大,如三条一样大,则比谁的两对大。如: | |
| ||
5 | Flush 五张同花 用五张同一花色但不相连的牌型组成,如都是五张同花,则谁的同花牌大谁赢。 | |
| ||
6 | Straight 五张顺子 由五张相连但不同花色的牌组成,在连牌中,Ace是既可作最大也可以作最小的牌。 | |
| | |
7 | Three-of-a-Kind 三条 即三张同样的牌。它有两种叫法,取决于一对牌是在您手中还是在桌上。一对在手中,桌上有一张,称之为“set”;v如手中有一张,桌上有一对,则称之为“Three of A Kind”。 | |
| | |
8 | Two Pair 两对 由五张牌中的两对牌组成。如果都有两对,则先比大对,再比小对 。 | |
| | |
9 | One Pair 一对 当不止一人有同样的一对牌时,则要比一对后面的牌,称之为“Kickers”。记住,德州扑克是挑选最好的五张牌去比。 | |
| | |
10 | High Card 大牌 无以上任何牌型时,决定牌的大小 。 |
题目大意:德州扑克,手里有5张牌,排队有5张牌,可以丢弃手里的N张牌,再从牌堆里抽取N张牌,求10张牌可以组成的最优牌面。
<pre class="sh-cpp sh-sourceCode" style="font-family:Courier New,Courier,monospace"><span class="sh-preproc">#include</span><span class="sh-string"><stdio.h></span> <span class="sh-preproc">#include</span><span class="sh-string"><string.h></span> <span class="sh-type">int</span> faceNum<span class="sh-symbol">,</span> binary<span class="sh-symbol">[</span><span class="sh-number">6</span><span class="sh-symbol">],</span> saveCard<span class="sh-symbol">,</span> record<span class="sh-symbol">[</span><span class="sh-number">6</span><span class="sh-symbol">],</span> count<span class="sh-symbol">[</span><span class="sh-number">6</span><span class="sh-symbol">];</span> <span class="sh-type">char</span> cardFace<span class="sh-symbol">[</span><span class="sh-number">10</span><span class="sh-symbol">][</span><span class="sh-number">20</span><span class="sh-symbol">]=</span><span class="sh-cbracket">{</span><span class="sh-string">"highest-card"</span><span class="sh-symbol">,</span><span class="sh-string">"one-pair"</span><span class="sh-symbol">,</span><span class="sh-string">"two-pairs"</span><span class="sh-symbol">,</span><span class="sh-string">"three-of-a-kind"</span><span class="sh-symbol">,</span><span class="sh-string">"straight"</span><span class="sh-symbol">,</span><span class="sh-string">"flush"</span><span class="sh-symbol">,</span><span class="sh-string">"full-house"</span><span class="sh-symbol">,</span><span class="sh-string">"four-of-a-kind"</span><span class="sh-symbol">,</span><span class="sh-string">"straight-flush"</span><span class="sh-cbracket">}</span><span class="sh-symbol">;</span> <span class="sh-keyword">struct</span><span class="sh-normal"> </span><span class="sh-classname">POC</span> <span class="sh-cbracket">{</span> <span class="sh-type">char</span> rank<span class="sh-symbol">,</span> suit<span class="sh-symbol">;</span> <span class="sh-type">int</span> num<span class="sh-symbol">;</span> <span class="sh-cbracket">}</span><span class="sh-symbol">;</span> <span class="sh-usertype">POC</span><span class="sh-normal"> </span>poc<span class="sh-symbol">[</span><span class="sh-number">15</span><span class="sh-symbol">],</span> hpoc<span class="sh-symbol">[</span><span class="sh-number">6</span><span class="sh-symbol">];</span> <span class="sh-type">void</span> <span class="sh-function">getCardFace</span><span class="sh-symbol">()</span> <span class="sh-cbracket">{</span> <span class="sh-type">int</span> fn <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">,</span> flush <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">,</span> stra <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>hpoc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>num <span class="sh-symbol">+</span> <span class="sh-number">1</span> <span class="sh-symbol">!=</span> hpoc<span class="sh-symbol">[</span>i <span class="sh-symbol">+</span> <span class="sh-number">1</span><span class="sh-symbol">].</span>num<span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> stra <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> <span class="sh-keyword">break</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>hpoc<span class="sh-symbol">[</span><span class="sh-number">1</span><span class="sh-symbol">].</span>num <span class="sh-symbol">==</span> <span class="sh-number">1</span> <span class="sh-symbol">&&</span> hpoc<span class="sh-symbol">[</span><span class="sh-number">2</span><span class="sh-symbol">].</span>num <span class="sh-symbol">==</span> <span class="sh-number">10</span> <span class="sh-symbol">&&</span> hpoc<span class="sh-symbol">[</span><span class="sh-number">3</span><span class="sh-symbol">].</span>num <span class="sh-symbol">==</span> <span class="sh-number">11</span> <span class="sh-symbol">&&</span> hpoc<span class="sh-symbol">[</span><span class="sh-number">4</span><span class="sh-symbol">].</span>num <span class="sh-symbol">==</span> <span class="sh-number">12</span> <span class="sh-symbol">&&</span> hpoc<span class="sh-symbol">[</span><span class="sh-number">5</span><span class="sh-symbol">].</span>num <span class="sh-symbol">==</span> <span class="sh-number">13</span><span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> stra <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>hpoc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>suit <span class="sh-symbol">!=</span> hpoc<span class="sh-symbol">[</span><span class="sh-number">5</span><span class="sh-symbol">].</span>suit<span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> flush <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> count<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> j <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> j <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> j<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>hpoc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>num <span class="sh-symbol">==</span> hpoc<span class="sh-symbol">[</span>j<span class="sh-symbol">].</span>num<span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> count<span class="sh-symbol">[</span>i<span class="sh-symbol">]++;</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-type">int</span> t<span class="sh-symbol">;</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> j <span class="sh-symbol">=</span> i <span class="sh-symbol">+</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> j <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> j<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>count<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">></span>count<span class="sh-symbol">[</span>j<span class="sh-symbol">])</span> <span class="sh-cbracket">{</span> t <span class="sh-symbol">=</span> count<span class="sh-symbol">[</span>i<span class="sh-symbol">];</span> count<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> count<span class="sh-symbol">[</span>j<span class="sh-symbol">];</span> count<span class="sh-symbol">[</span>j<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> t<span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>count<span class="sh-symbol">[</span><span class="sh-number">5</span><span class="sh-symbol">]</span> <span class="sh-symbol">==</span> <span class="sh-number">2</span><span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>count<span class="sh-symbol">[</span><span class="sh-number">2</span><span class="sh-symbol">]</span> <span class="sh-symbol">+</span> count<span class="sh-symbol">[</span><span class="sh-number">3</span><span class="sh-symbol">]</span> <span class="sh-symbol">==</span> <span class="sh-number">4</span><span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">2</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>count<span class="sh-symbol">[</span><span class="sh-number">5</span><span class="sh-symbol">]</span> <span class="sh-symbol">==</span> <span class="sh-number">3</span><span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span><span class="sh-number">3</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>stra<span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">4</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>flush<span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>count<span class="sh-symbol">[</span><span class="sh-number">2</span><span class="sh-symbol">]</span> <span class="sh-symbol">+</span> count<span class="sh-symbol">[</span><span class="sh-number">3</span><span class="sh-symbol">]</span> <span class="sh-symbol">==</span> <span class="sh-number">5</span><span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">6</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>count<span class="sh-symbol">[</span><span class="sh-number">2</span><span class="sh-symbol">]</span> <span class="sh-symbol">==</span> <span class="sh-number">4</span><span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">7</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>stra <span class="sh-symbol">&&</span> flush<span class="sh-symbol">)</span> fn <span class="sh-symbol">=</span> <span class="sh-number">8</span><span class="sh-symbol">;</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>fn <span class="sh-symbol">></span> faceNum<span class="sh-symbol">)</span> faceNum <span class="sh-symbol">=</span> fn<span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-type">int</span> <span class="sh-function">main</span><span class="sh-symbol">()</span> <span class="sh-cbracket">{</span> <span class="sh-type">int</span> num<span class="sh-symbol">[</span><span class="sh-number">15</span><span class="sh-symbol">];</span> <span class="sh-keyword">while</span> <span class="sh-symbol">(</span><span class="sh-function">scanf</span><span class="sh-symbol">(</span><span class="sh-string">"%c%c"</span><span class="sh-symbol">,</span> <span class="sh-symbol">&</span>poc<span class="sh-symbol">[</span><span class="sh-number">1</span><span class="sh-symbol">].</span>rank<span class="sh-symbol">,</span> <span class="sh-symbol">&</span>poc<span class="sh-symbol">[</span><span class="sh-number">1</span><span class="sh-symbol">].</span>suit<span class="sh-symbol">)</span> <span class="sh-symbol">==</span> <span class="sh-number">2</span><span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">2</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><=</span> <span class="sh-number">10</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-function">scanf</span><span class="sh-symbol">(</span><span class="sh-string">" %c%c"</span><span class="sh-symbol">,</span> <span class="sh-symbol">&</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank<span class="sh-symbol">,</span> <span class="sh-symbol">&</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>suit<span class="sh-symbol">);</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><=</span> <span class="sh-number">10</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank <span class="sh-symbol">==</span> <span class="sh-string">'T'</span><span class="sh-symbol">)</span> num<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> <span class="sh-number">10</span><span class="sh-symbol">;</span> <span class="sh-keyword">else</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank <span class="sh-symbol">==</span> <span class="sh-string">'J'</span><span class="sh-symbol">)</span> num<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> <span class="sh-number">11</span><span class="sh-symbol">;</span> <span class="sh-keyword">else</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank <span class="sh-symbol">==</span> <span class="sh-string">'Q'</span><span class="sh-symbol">)</span> num<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> <span class="sh-number">12</span><span class="sh-symbol">;</span> <span class="sh-keyword">else</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank <span class="sh-symbol">==</span> <span class="sh-string">'K'</span><span class="sh-symbol">)</span> num<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> <span class="sh-number">13</span><span class="sh-symbol">;</span> <span class="sh-keyword">else</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank <span class="sh-symbol">==</span> <span class="sh-string">'A'</span><span class="sh-symbol">)</span> num<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> <span class="sh-keyword">else</span> num<span class="sh-symbol">[</span>i<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> poc<span class="sh-symbol">[</span>i<span class="sh-symbol">].</span>rank <span class="sh-symbol">-</span> <span class="sh-string">'0'</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> faceNum <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> i <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> i <span class="sh-symbol"><</span> <span class="sh-number">32</span><span class="sh-symbol">;</span> i<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-type">int</span> cnt <span class="sh-symbol">=</span> <span class="sh-number">5</span><span class="sh-symbol">,</span> j <span class="sh-symbol">=</span> i<span class="sh-symbol">;</span> saveCard <span class="sh-symbol">=</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> <span class="sh-function">memset</span><span class="sh-symbol">(</span>binary<span class="sh-symbol">,</span> <span class="sh-number">0</span><span class="sh-symbol">,</span> <span class="sh-keyword">sizeof</span><span class="sh-symbol">(</span>binary<span class="sh-symbol">));</span> <span class="sh-function">memset</span><span class="sh-symbol">(</span>record<span class="sh-symbol">,</span> <span class="sh-number">0</span><span class="sh-symbol">,</span> <span class="sh-keyword">sizeof</span><span class="sh-symbol">(</span>record<span class="sh-symbol">));</span> <span class="sh-keyword">while</span> <span class="sh-symbol">(</span>j <span class="sh-symbol">></span> <span class="sh-number">0</span><span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> binary<span class="sh-symbol">[</span>cnt<span class="sh-symbol">--]</span> <span class="sh-symbol">=</span> j <span class="sh-symbol">%</span> <span class="sh-number">2</span><span class="sh-symbol">;</span> j <span class="sh-symbol">=</span> j <span class="sh-symbol">/</span> <span class="sh-number">2</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-comment">// printf("%d %d %d %d %d\n", binary[1], binary[2], binary[3], binary[4], binary[5]);</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span>j <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> j <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> j<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(!</span>binary<span class="sh-symbol">[</span>j<span class="sh-symbol">])</span> <span class="sh-cbracket">{</span> saveCard<span class="sh-symbol">++;</span> record<span class="sh-symbol">[</span>saveCard<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> j<span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span>j <span class="sh-symbol">=</span> saveCard <span class="sh-symbol">+</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> j <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> j<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> record<span class="sh-symbol">[</span>j<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> j <span class="sh-symbol">-</span> saveCard <span class="sh-symbol">+</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-comment">// printf("%d %d %d %d %d\n\n", record[1], record[2], record[3], record[4], record[5]);</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span>j <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> j <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> j<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> hpoc<span class="sh-symbol">[</span>j<span class="sh-symbol">].</span>suit <span class="sh-symbol">=</span> poc<span class="sh-symbol">[</span>record<span class="sh-symbol">[</span>j<span class="sh-symbol">]].</span>suit<span class="sh-symbol">;</span> hpoc<span class="sh-symbol">[</span>j<span class="sh-symbol">].</span>num <span class="sh-symbol">=</span> num<span class="sh-symbol">[</span>record<span class="sh-symbol">[</span>j<span class="sh-symbol">]];</span> <span class="sh-cbracket">}</span> <span class="sh-usertype">POC</span><span class="sh-normal"> </span>temp<span class="sh-symbol">;</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> k <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> k <span class="sh-symbol"><</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> k<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span>j <span class="sh-symbol">=</span> k <span class="sh-symbol">+</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> j <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> j<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-keyword">if</span> <span class="sh-symbol">(</span>hpoc<span class="sh-symbol">[</span>k<span class="sh-symbol">].</span>num <span class="sh-symbol">></span> hpoc<span class="sh-symbol">[</span>j<span class="sh-symbol">].</span>num<span class="sh-symbol">)</span> <span class="sh-cbracket">{</span> temp <span class="sh-symbol">=</span> hpoc<span class="sh-symbol">[</span>k<span class="sh-symbol">];</span> hpoc<span class="sh-symbol">[</span>k<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> hpoc<span class="sh-symbol">[</span>j<span class="sh-symbol">];</span> hpoc<span class="sh-symbol">[</span>j<span class="sh-symbol">]</span> <span class="sh-symbol">=</span> temp<span class="sh-symbol">;</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-cbracket">}</span> <span class="sh-function">getCardFace</span><span class="sh-symbol">();</span> <span class="sh-comment">// printf("%d %c\n", hpoc[1].num, hpoc[1].suit);</span> <span class="sh-cbracket">}</span> <span class="sh-comment">// printf("%d\n", faceNum);</span> <span class="sh-function">printf</span><span class="sh-symbol">(</span><span class="sh-string">"Hand: "</span><span class="sh-symbol">);</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> k <span class="sh-symbol">=</span> <span class="sh-number">1</span><span class="sh-symbol">;</span> k <span class="sh-symbol"><=</span> <span class="sh-number">5</span><span class="sh-symbol">;</span> k<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-function">printf</span><span class="sh-symbol">(</span><span class="sh-string">"%c%c "</span><span class="sh-symbol">,</span> poc<span class="sh-symbol">[</span>k<span class="sh-symbol">].</span>rank<span class="sh-symbol">,</span> poc<span class="sh-symbol">[</span>k<span class="sh-symbol">].</span>suit<span class="sh-symbol">);</span> <span class="sh-cbracket">}</span> <span class="sh-function">printf</span><span class="sh-symbol">(</span><span class="sh-string">"Deck: "</span><span class="sh-symbol">);</span> <span class="sh-keyword">for</span> <span class="sh-symbol">(</span><span class="sh-type">int</span> k <span class="sh-symbol">=</span> <span class="sh-number">6</span><span class="sh-symbol">;</span> k <span class="sh-symbol"><=</span> <span class="sh-number">10</span><span class="sh-symbol">;</span> k<span class="sh-symbol">++)</span> <span class="sh-cbracket">{</span> <span class="sh-function">printf</span><span class="sh-symbol">(</span><span class="sh-string">"%c%c "</span><span class="sh-symbol">,</span> poc<span class="sh-symbol">[</span>k<span class="sh-symbol">].</span>rank<span class="sh-symbol">,</span> poc<span class="sh-symbol">[</span>k<span class="sh-symbol">].</span>suit<span class="sh-symbol">);</span> <span class="sh-cbracket">}</span> <span class="sh-function">printf</span><span class="sh-symbol">(</span><span class="sh-string">"Best hand: %s</span><span class="sh-specialchar">\n</span><span class="sh-string">"</span><span class="sh-symbol">,</span> cardFace<span class="sh-symbol">[</span>faceNum<span class="sh-symbol">]);</span> <span class="sh-function">getchar</span><span class="sh-symbol">();</span> <span class="sh-cbracket">}</span> <span class="sh-keyword">return</span> <span class="sh-number">0</span><span class="sh-symbol">;</span> <span class="sh-cbracket">}</span>
uva 131 The Psychic Poker Player (暴力枚举)
原文地址:http://blog.csdn.net/llx523113241/article/details/43082985