The Psychic Poker Player

Source: Internet
Author: User


I have five cards on my hand and five cards on the stack. Now I want to discard the n (0 <= n <= 5) cards on my hand, take n cards from the heap. If you have a special function, you can know what the five cards on the heap are from top to bottom. You must obtain the largest card at the end, A card consists of numbers and colors.

Train of Thought: I will give you one by one each kind of case and then judge (children who do not know how to play cards cannot afford to hurt this question)

Code:
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Struct node
{
Char str [3];
} E [12], ee [12], ans [12];
Int p = 0, max = 0;
Char str [] [19] = {"highest-card", "one-pair", "two-pairs", "three-of-a-kind ",
"Straight", "flush", "full-house", "four-of-a-kind", "straight-flush "};
Char str1 [19] = "123456789:; <=", str2 [10] = "CDHS ";
Int cmp (void const * a, void const * B)
{
Return (* (struct node *) a). str [0]-(* (struct node *) B). str [0];
}
Void change (int p)
{
If (ee [p]. str [0] = 'A') {ee [p]. str [0] = '1'; return ;}
If (ee [p]. str [0] = 'T') {ee [p]. str [0] = ':'; return ;}
If (ee [p]. str [0] = 'J') {ee [p]. str [0] = '; return ;}
If (ee [p]. str [0] = 'q') {ee [p]. str [0] = '<'; return ;}
If (ee [p]. str [0] = 'k') {ee [p]. str [0] = '; return ;}
Return;
}
Int judge ()
{
Int I = 0, p = 0, num1 [5], num2 [5];
Char ans1 [10], ans2 [10];
Qsort (ans, 5, sizeof (ans [0]), cmp); // The characters in ans can be regarded as numbers from 1 to 13.
For (I = 0; I <5; I ++)
{
Num1 [I] = num2 [I] = 1;
}
For (I = 0; I <5; I ++)
{
Ans1 [I] = ans [I]. str [0]; // obtain the nominal value
Ans2 [I] = ans [I]. str [1]; // color
If (I)
{
If (ans1 [I] = ans1 [I-1]) // record the number of times
Num1 [I] + = num1 [I-1];
If (ans2 [I] = ans2 [I-1])
Num2 [I] + = num2 [I-1];
}
}
P = ans1 [0]-'1 ';
If (p <10 & strncmp (ans1, str1 + p, 5) = 0 & num2 [4] = 5)
Return 8;
If (ans1 [0] = '1' & ans1 [1] = ':' & ans1 [2] = '; '& ans1 [3] =' <'& ans1 [4] =' & num2 [4] = 5)
Return 8;
If (num1 [3] = 4 | num1 [4] = 4)
Return 7;
If (num1 [2] = 3 & num1 [4] = 2) | (num1 [1] = 2 & num1 [4] = 3 ))
Return 6;
If (num2 [4] = 5)
Return 5;
If (p <10 & strncmp (ans1, str1 + p, 5) = 0)
Return 4;
If (ans1 [0] = '1' & ans1 [1] = ':' & ans1 [2] = '; '& ans1 [3] =' <'& ans1 [4] = ')
Return 4;
If (num1 [4] = 3 & num1 [0] = 1 & num1 [1] = 1) | (num1 [3] = 3 & num1 [0] = 1 & num1 [4] = 1) | (num1 [2] = 3 & num1 [4] = 1 ))
Return 3;
If (num1 [1] = 2 & num1 [3] = 2 & num1 [4] = 1) | (num1 [2] = 2 & num1 [4] = 2) | (num1 [1] = 2 & num1 [4] = 2 ))
Return 2;
If (num1 [2] = 2) | (num1 [3] = 2) | (num1 [4] = 2) | (num1 [1] = 2 ))
Return 1;
Return 0;
}
Void create (int cu, int p) // enumerate each case
{
Int I = 0, j = 0, k = 0;
If (cu = 6)
{
For (j = p, I = 5; I <= 9-p; I ++)
{
Strcpy (ee [j ++]. str, e [I]. str );
Change (J-1 );
}
For (I = 0; I <5; I ++)
Strcpy (ans [I]. str, ee [I]. str );
K = judge ();
Max = max> k? Max: k;
Return;
}
For (I = 0; I <2; I ++)
{
If (I)
{
Strcpy (ee [p]. str, e [cu-1]. str );
Change (p );
Create (cu + 1, p + 1 );
}
Else
Create (cu + 1, p );
}
}
Int main ()
{
Int I = 0;
While (scanf ("% s", e [0]. str )! = EOF)
{
Printf ("Hand :");
Printf ("% s", e [0]. str );
For (I = 1; I <10; I ++)
{
Scanf ("% s", e [I]. str );
If (I = 5)
Printf ("Deck :");
Printf ("% s", e [I]. str );
}
Printf ("Best hand :");
Max = p = 0;
Create (1, p );
Printf ("% s \ n", str [max]);
} Www.2cto.com
Return 0;
}


Author: ulquiorra0cifer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.