UVa 131 The Psychic Poker Player
题目大意:手上有5张牌, 堆上有5张牌, 现在要求舍弃手上的n(0<=n<=5)牌, 从堆的面上拿n张牌, 假设了你有特异功能, 可以知道堆上的5张牌从上到下是是什么, 要求最后得到的牌要面值最大, 一张牌由数字与花色组成。
思路:就是一一枚举出每种请况, 然后判断(不懂打牌的孩子这道题伤不起啊)
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);//ans中的字符可以看成1到13的数字
for(i = 0; i<5; i++)
{
num1[i] = num2[i] = 1;
}
for(i = 0; i<5; i++)
{
ans1[i] = ans[i].str[0];//取面值
ans2[i] = ans[i].str[1];//取花色
if(i)
{
if(ans1[i] == ans1[i-1])//记录出 现次数
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)//枚举每种情况
{
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);
}
&n
补充:软件开发 , C语言 ,