A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or spades (denoted C, D, H, S in the input data). Each card also has a value which is one of 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace (denoted 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A). For scoring purposes, the suits are unordered while the values are ordered as given above, with 2 being the lowest and ace the highest value.

A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest

  • High Card. Hands which do not fit any higher category are ranked by the value of their highest card. If the highest cards have the same value, the hands are ranked by the next highest, and so on.
  • Pair. 2 of the 5 cards in the hand have the same value. Hands which both contain a pair are ranked by the value of the cards forming the pair. If these values are the same, the hands are ranked by the values of the cards not forming the pair, in decreasing order.
  • Two Pairs. The hand contains 2 different pairs. Hands which both contain 2 pairs are ranked by the value of their highest pair. Hands with the same highest pair are ranked by the value of their other pair. If these values are the same the hands are ranked by the value of the remaining card.
  • Three of a Kind. Three of the cards in the hand have the same value. Hands which both contain three of a kind are ranked by the value of the 3 cards.
  • Straight. Hand contains 5 cards with consecutive values. Hands which both contain a straight are ranked by their highest card.
  • Flush. Hand contains 5 cards of the same suit. Hands which are both flushes are ranked using the rules for High Card.
  • Full House. 3 cards of the same value, with the remaining 2 cards forming a pair. Ranked by the value of the 3 cards.
  • Four of a kind. 4 cards with the same value. Ranked by the value of the 4 cards.
  • Straight flush. 5 cards of the same suit with consecutive values. Ranked by the highest card in the hand.

Your job is to compare several pairs of poker hands and to indicate which, if either, has a higher rank.

Input Specification

Several lines, each containing the designation of 10 cards: the first 5 cards are the hand for the player named "Black" and the next 5 cards are the hand for the player named "White."

Output Specification

For each line of input, print a line containing one of:

   Black wins.
White wins.
Tie.

Sample Input

2H 3D 5S 9C KD 2C 3H 4S 8C AH
2H 4S 4C 2D 4H 2S 8S AS QS 3S
2H 3D 5S 9C KD 2C 3H 4S 8C KH
2H 3D 5S 9C KD 2D 3H 5C 9S KH

Sample Output

White wins.
Black wins.
Black wins.
Tie.
 
题意:又是一道模拟题,好久没敲过模拟题了,这次敲了蛮久,还记得暑假由此做某个地方的省赛,也是一道模拟题,那道题是打麻将,这次变成玩扑克了。
题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小)
同花顺:牌面一样,只比较最大的看谁大,一样大则平手
四条:四个一样的,看这四个一样的中谁大谁赢
葫芦:三条+一对,看三条中谁的牌面大
同花:都是同花就按从大到小比较,看谁的更大
顺子:都是顺子看最大的谁大,一样则平手
三条:三条看三条中谁的牌面大
两对:两对就看谁的对子大,都一样大比单牌
一对:比对子,一样则比单牌
单排:按顺序比较大小,大者胜
 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; struct node
{
int num,mark;
} white[10],black[10]; int cmp(node a,node b)
{
return a.num<b.num;
} int set(char c)
{
if(c<='9' && c>='2')
return c-'0';
if(c == 'T')
return 10;
if(c == 'J')
return 11;
if(c == 'Q')
return 12;
if(c == 'K')
return 13;
if(c == 'A')
return 14;
if(c == 'C')
return 1;
if(c == 'D')
return 2;
if(c == 'H')
return 3;
if(c == 'S')
return 4;
} int up[10]; int same(node *a)
{
int i,l = 0;
for(i = 2; i<=5; i++)
if(a[i].num!=a[i-1].num)
up[l++] = i;
return l;
}
/*
我们用数字表示牌面
1-同花顺
2-四条
3-葫芦
4-同花
5-顺子
6-三条
7-两对
8-一对
9-单牌
*/
int judge(node *a)
{
int flag1 = 0;
int flag2 = 0;
if(a[1].mark == a[2].mark && a[2].mark == a[3].mark &&a[3].mark == a[4].mark &&a[4].mark == a[5].mark)
flag1 = 1;
if(a[1].num+1 == a[2].num && a[2].num+1 == a[3].num &&a[3].num+1 == a[4].num &&a[4].num+1 == a[5].num)
flag2 = 1;
if(flag1 && flag2)
return 1;
else if(flag1 && !flag2)
return 4;
else if(flag2 && !flag1)
return 5;
int k = same(a);
if(k == 0)
return 2;
else if(k == 1)
{
if(up[0] == 2 || up[0] == 5)
return 2;
if(up[0] == 3 || up[0] == 4)
return 3;
}
else if(k == 2)
{
if(up[0] == 2 && up[1] == 3 || up[0] == 4 && up[1] == 5 || up[0] == 2 && up[1] == 5)
return 6;
else
return 7;
}
else if(k == 3)
return 8;
else if(k == 4)
return 9;
return 0;
} int find_one(node *a)
{
int i;
for(i = 1; i<=5; i++)
{
if(i == 1 && a[i].num!=a[i+1].num)
return 1;
if(i == 5 && a[i].num!=a[i-1].num)
return 5;
if(a[i].num!=a[i-1].num && a[i].num!=a[i+1].num)
return i;
}
return 0;
} int find_pair(node *a)
{
int i;
for(i = 1; i<=5; i++)
{
if(i == 1 && a[i].num == a[i+1].num)
return 2;
if(a[i].num == a[i-1].num)
return i;
}
return 0;
} int compare(int x)
{
int i,j,a,b;
if(x == 1 || x == 5)
{
if(white[5].num>black[5].num)
return -1;
else if(white[5].num<black[5].num)
return 1;
return 0;
}
else if(x == 2 || x == 3 || x == 6)
{
if(white[3].num>black[3].num)
return -1;
else if(white[3].num<black[3].num)
return 1;
return 0;
}
else if(x == 4 || x == 9)
{
for(i = 5; i>=1; i--)
{
if(black[i].num<white[i].num)return -1;
else if(black[i].num>white[i].num)
return 1;
}
return 0;
}
else if(x == 7)
{
if(white[4].num>black[4].num)
return -1;
else if(white[4].num<black[4].num)
return 1;
else
{
if(white[2].num>black[2].num)
return -1;
else if(white[2].num<black[2].num)
return 1;
int a = find_one(white);
int b = find_one(black);
if(black[b].num<white[a].num)
return -1;
else if(black[b].num>white[a].num)
return 1;
return 0;
}
}
else if(x == 8)
{
int a = find_pair(white);
int b = find_pair(black);
int tem_w[10],tem_b[10],i,lb = 1,lw = 1;
if(white[a].num>black[b].num)
return -1;
else if(white[a].num<black[b].num)
return 1;
for(i = 1; i<=5; i++)
{
if(i!=a && i!=a-1)
tem_w[lw++] = white[i].num;
if(i!=b && i!=b-1)
tem_b[lb++] = black[i].num;
}
for(i = 3; i>=1; i--)
{
if(tem_w[i]>tem_b[i])
return -1;
else if(tem_b[i]>tem_w[i])
return 1;
}
return 0;
}
return 0;
} int main()
{
char str[5];
int sumb,sumw,j,k,i;
while(~scanf("%2s",str))
{
j = 1;
k = 1;
black[j].num = set(str[0]);
black[j++].mark = set(str[1]);
for(i = 2; i<=10; i++)
{
scanf("%2s",str);
if(i<6)
{
black[j].num = set(str[0]);
black[j++].mark = set(str[1]);
}
else
{
white[k].num = set(str[0]);
white[k++].mark = set(str[1]);
}
}
sort(black+1,black+6,cmp);
sort(white+1,white+6,cmp);
sumb = judge(black);
sumw = judge(white);
if(sumb>sumw)
printf("White wins.\n");
else if(sumb<sumw)
printf("Black wins.\n");
else
{
int flag = compare(sumb);
if(flag == -1)
printf("White wins.\n");
else if(flag == 1)
printf("Black wins.\n");
else
printf("Tie.\n");
}
} return 0;
}

ZOJ1111:Poker Hands(模拟题)的更多相关文章

  1. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  2. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  3. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  5. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  6. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  7. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

  8. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  9. URAL 2046 A - The First Day at School 模拟题

    A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

随机推荐

  1. update多表陷阱

    今天同学发了个sql题目 A1表 B1表 id num id snum 1 10 1 90 2 2000 3 4000 3 30 B表的数据插入A表当中 最后的结果 A表 1 90 2 2000 3 ...

  2. border-radius的水平和竖直半径

    通常我们设置border-radius都只区分四个角的, 如border-radius: 1em 2em. 其实每个角的border-radius都由两部分组成, 水平半径和竖直半径. 要设置水平和竖 ...

  3. 中断服务程序不用interrupt关键字也可实现中断,该关键字是否必须?

    2013-06-20 11:13:35 中断服务程序不用interrupt关键字也可实现中断,该关键字是否必须? 使用tools->pin connect,将INT5与pin.txt关联,模拟外 ...

  4. Linux内核与根文件系统的关系1

    Linux内核与根文件系统的关系开篇题外话:对于Linux初学者来说,这是一个很纠结的问题,但这也是一个很关键的问题!一语破天机: “尽管内核是 Linux 的核心,但文件却是用户与操作系统交互所采用 ...

  5. UVa 1637 (概率) Double Patience

    题意: 一共有9堆牌,每堆牌四张.每次可以取堆顶点数相同的两张牌,如果有多种方案则选取是随机的. 如果最后将所有牌取完,则视为游戏胜利,求胜利的概率. 分析: 用一个九元组表示状态,分别代表每堆牌剩余 ...

  6. SCOI2009windy数

    数位DP,还不怎么会…… 其中calc函数的计算分为三部分: 第一部分:统计最高位为0的情况,或者说不足最高位位数的数的个数 第二部分:统计最高位为1到a[len]-1的情况,直接调用数组即可 第三部 ...

  7. 扩展Oracle表空间

    1. 查看当前表空间利用率SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)" ...

  8. Hibernate4.x之映射关系--双向1-n

    双向1-n与双向n-1是完全相同的两种情形 双向1-n需要在1的一端可以访问n的一端,反之亦然. 域模型:从Order到Customer的多对一双向关联需要在Order类中定义一个Customer属性 ...

  9. java.lang和java.lang.annotation中实现Annotation的类小结

    加了注解,等于打上了某种标记,没加,则等于没有某种标记,以后,其他程序可以用反射来了解你的类上面有无何种标记,看你有什么标记,就去干相应的事.标记可以加在类,方法,字段,包上,方法的参数上. (1)  ...

  10. CF GYM 100703G Game of numbers

    题意:给n个数,一开始基数为0,用这n个数依次对基数做加法或减法,使基数不超过k且不小于0,输出最远能运算到的数字个数,输出策略. 解法:dp.dp[i][j]表示做完第i个数字的运算后结果为j的可能 ...