照着题目的输入是正确的,但是我没有测试过,但是提交上去是错误的,可能本人技术比较烂吧,提交的题目都是Wrong answer

Problem D

Poker Hands

Input: standard input

Output: standardoutput

Time Limit: 2 seconds

Memory Limit: 32 MB

A poker deck contains 52 cards - each card has a suit whichis one of clubs, diamonds, hearts, or spades (denoted C, D, H, and 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 asgiven 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 thefollowing 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 pokerhands and to indicate which, if either, has a higher rank.

Input

The input file contains severallines, each containing the designation of 10cards: the first 5 cards are thehand for the player named "Black"and the next 5 cards are the handfor the player named "White".

Output

For each line of input, print a line containing one of thefollowing three lines:

 
   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.

我写的代码:

#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <cstring>
using namespace std;
#define  NCARDS 52
#define  NSUITS 4
char values[] = "23456789TJQKA";
char types[]  = "CDHS";
char white[] = "White wins.";
char black[] = "Black wins.";
char tie  [] = "Tie.";
int rank_card(char value , char type)
{int i,j;for (i = 0 ; i < NCARDS; ++i ){if (value == values[i]){for (j = 0 ; j < NSUITS ; ++j){if (type == types[j]){return (i*NSUITS+j);}}}}fprintf(stderr,"bad card\n");return -1;
}
char card_type(int card)
{return types[card%4];
}
char card_value(int card)
{return values[card/4];
}
bool is_order(int arr[])
{char str[6] = "";int i = 0;for( ; i < 5 ; i++)str[i] = card_value(arr[i]);char* rc = search(values,values+13,str,str+5);return (rc!=values+13);
}
bool is_same_type(int arr[])
{int i = 1;for(; i < 5 ; i ++){if(card_type(arr[i]) != card_type(arr[i-1]))return false;}return true;
}
int  get_level_type(int arr[])
{char ch = card_value(arr[0]);int level_type = 0;int i ;int nsame= 1;int ndouble = 0 , nthree = 0 , nfour = 0;for(i = 1; i < 5 ; ++i){if(ch == card_value(arr[i])){nsame++;}else{ch = card_value(arr[i]);if(nsame == 2){ndouble++;}else if(nsame == 3){nthree++;}else if (nsame == 4){nfour++;}nsame = 1;}}if(nsame == 2){ndouble++;}else if(nsame == 3){nthree++;}else if (nsame == 4){nfour++;}assert(!(nthree&&nfour));assert(ndouble < 3);if(nfour){level_type = (1<<6);return level_type;}if(ndouble == 2)//双对{level_type  = ndouble;return level_type;}else if(ndouble ==1)//一对{printf("yi dui \n");level_type = ndouble;}if(nthree)//三张{level_type |= (1<<2);if(ndouble ==1){level_type |= (1<<5);//葫芦}return level_type;}if(ndouble)        //如果 有一对 则不用检查 顺子和同花;return level_type;if(is_same_type(arr))//同花{level_type = (1<<4);}if (is_order(arr))//顺子{level_type |= (1<<3);}if( (level_type & (1<<4))  && (level_type & (1<<3)) ){level_type |= (1<<7);}return level_type;
}
int same_level_cmp(int arr1[],int level_type1 , int arr2[],int leve_type2)
{int i = 0;int arr1_1,arr1_2,arr2_1,arr2_2;//检测双对if( !level_type1  || (level_type1&(1 << 4)) || (level_type1&(1<<3)))  //同花 顺子 最大牌 归为一类 , 选择两幅牌的最大牌{for(i = 4 ; i >=0 ; i--){if (card_value(arr1[i]) != card_value(arr2[i])){return arr2[i]-arr1[i];}}}if( (level_type1&(1<<6)) || (level_type1&(1<<2)))  //四张 三张(包括葫芦)  归为一类  只要检测五张牌的中间那张{printf("duo zhang");return arr2[2] - arr1[2];}if( (level_type1&(1<<1)) ) //双对{printf("shuang dui\n");arr1_1 = arr1[1];arr1_2 = arr1[3];if(arr1_1 > arr1_2) swap(arr1_1,arr1_2);arr2_1 = arr2[1];arr2_2 = arr2[3];if (arr2_1 > arr2_2) swap(arr2_1,arr2_2);if(arr1_2 != arr2_2) return arr2_2 - arr1_2;else              return arr2_1 - arr1_1;}if( (level_type1&(1)) )//一对{printf("yi dui\n");for (i = 1 ; i < 5 ; i ++){if (card_value(arr1[i]) == card_value(arr1[i-1])){arr1_1 = arr1[i];break;}}for (i = 1; i < 5 ; i ++){if(card_value(arr2[i]) == card_value(arr2[i-1])){arr2_1 = arr2[i];break;}}if(arr1_1 != arr2_1) return arr1_1 - arr2_1;for (i = 4 ; i >= 0 ; i--){if(card_value(arr1[i]) != card_value(arr2[i]))return arr2[i] - arr1[i];}}return 0;
}
int get_result(int arr1[] , int arr2[])
{int level_type1 = 0 , level_type2 = 0;sort(arr1,arr1+5);sort(arr2,arr2+5);level_type1 = get_level_type(arr1);level_type2 = get_level_type(arr2);if (level_type1 > level_type2){return -1;}else if(level_type1 < level_type2){return 1;}return  same_level_cmp( arr1,level_type1 ,  arr2, level_type2);
}
int main()
{char str[1000];char *p = NULL;int i = 0;int result = 0;memset(str,0,1000);int array[10] = {0};while(gets(str)){i = 0;p = strtok(str," ");while (p){array[i++] = rank_card(p[0],p[1]);p = strtok(NULL," ");}//    result =get_result(array,array+5);if ( ( result=get_result(array,array+5)) < 0 ){printf("%s\n",black);}else if(result > 0){printf("%s\n",white);}else{printf("%s\n",tie);}memset(str,0,1000);}return 0;
}//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
// 2C 2D 2S 2H 3S 5S 6S 7D 8S AS

一道狗血的ACM题:Poker Hands相关推荐

  1. ACM题集以及各种总结大全(转)

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  2. “蔚来杯“2022牛客暑期多校训练营8 D题: Poker Game: Decision

    D题: Poker Game: Decision 原题链接:https://ac.nowcoder.com/acm/contest/33193/D 题目大意 在德州扑克的大小比较规则情况下,发牌顺序与 ...

  3. [3.3训练赛]One-Dimensional(矩阵快速幂),Freda的迷宫(无向图强连通分量+并查集),一道防AK好题

    文章目录 T1:One-Dimensional title solution code T2:[NOIP模拟赛]Freda的迷宫 title solution code T3:[NOIP模拟赛]一道防 ...

  4. 【训练计划】ACM题集以及各种总结大全

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  5. ACM题集以及各种总结大全

    ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...

  6. 一道反序列化的CTF题分享

    文章目录 一.源码分析 二.传参分析 三.小结 一.源码分析 首先看源代码: <?php Class readme{public function __toString(){return hig ...

  7. 1.计蒜客ACM题库.A1001 整除问题

    计蒜客ACM题库.A1001 整除问题 判断一个数是否能被另一个整数整除是一个挺简单的问题,一般一个模运算就可以搞定了,懒惰的晓萌还是不想自己做,于是找到你帮他写代码,你就帮帮他吧. 输入格式 输入包 ...

  8. 5.计蒜客ACM题库.A2234 结果填空:青蛙爬井

    计蒜客ACM题库.A2234 结果填空:青蛙爬井 有一口深度为 high 米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬 up 米,夜里则顺井壁向下滑 down 米. 若青蛙从某个早晨开始向外爬 ...

  9. 一道小学奥数题的编程解法

    一道小学奥数题的编程解法 这是一道小学奥数题,看到这一题后如果只给我笔和纸,我真的无从下手,不知怎么去把这些方框填出来.但借助编程,这道题就非常简单了.直接送上代码. C++程序代码 #include ...

  10. A. 这是一道简单的水题~

    A. 这是一道简单的水题~ pbz最近沉浸在数学中无法自拔,他发现了一种非常有趣的数,这个数的十进制表示形式中只含有8和9,这个数有着很好的寓意,代表了pbz的梦想和期望,他想知道对于任意的给定的正整 ...

最新文章

  1. html5 点击事件委托,jquery事件委托
  2. [SCOI 2010]字符串
  3. 本地离线语音识别芯片哪家强
  4. window创建计划自动启动服务器,WINDOWS2008计划任务无法启动
  5. 【深度学习之美笔记】人工“碳”索意犹尽,智能“硅”来未可知(入门系列之二)
  6. android基础教程:多个页面时如何设置首页
  7. 如何恢复计算机永久删除文件,怎么恢复被彻底删除的文件?简单有效方法分享...
  8. 主干分支开发模式_源代码主干分支开发四大模式
  9. 磁珠和电感有什么区别_电感和磁珠的作用
  10. Kindle接入HomeAssistant:实现锁屏壁纸显示HA内设备信息并在HA内获取Kindle电量
  11. Linux - 查看、修改、更新系统时间
  12. 虚拟化技术之KVM,搭建KVM(详细)
  13. 怎样删除具有trustedinstall权限的文件
  14. 互联网公司的几种“死法”
  15. Android通话录音流程
  16. 基于向量加权平均算法的函数寻优和工程优化
  17. 《计算机网络自顶向下方法》读书笔记(一):计算机网络和因特网
  18. 通俗解释网络语到底什么是PTSD?什么是饭圈PTSD?
  19. 揭秘vue-sfc-cli: 组件研发利器
  20. INFOCOM 历年最佳论文汇总Topic推荐-AMiner

热门文章

  1. 删库跑路最佳实践总结
  2. kali 基于虚拟机下载
  3. 【人工智能】传教士和野人问题(M-C问题)
  4. java邮件发送 qq与163邮箱互发和qq和163邮箱发送其他邮箱实例
  5. WORD/OFFICE排版时插入脚注和分栏冲突的解决方法
  6. nohup java_nohup
  7. PMI-ACP敏捷项目认证练习题(二)
  8. tf改善_如何衡量和改善自动常见问题解答
  9. java虚拟机-d参数配置_Java虚拟机-JVM各种参数配置大全详细
  10. signature=56b13ba141d8042e7f17a5bffcc46d8e,vue 汉字转成拼音