ACM: Poker Game

2023-11-16

题目描述

A poker deck contains 52 cards. Each card has a suit of either clubs, diamonds, hearts, or spades (denoted C, D, H, S in the input data). Each card also has a value of either 2 through 10, jack, queen, king, or ace (denoted 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A). For scoring purposes card values are ordered as above, with 2 having the lowest and ace the highest value. The suit has no impact on value.
A poker hand consists of five cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest.
(1)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.For example:8C 9D 2H 3S 4H
(2)Pair:
Two of the five 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.For example:8C 8D 2H 3S 4H
(3)Two Pairs:
The hand contains two different pairs. Hands which both contain two 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.For example:8C 8D 2H 2S 4H
(4)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 three cards.For example:8C 8D 8H 3S 4H
(5)Straight:
Hand contains five cards with consecutive values. Hands which both contain a straight are ranked by their highest card.For example:2C 3D 4H 5S 6H
(6)Flush:
Hand contains five cards of the same suit. Hands which are both flushes are ranked using the rules for High Card.For example:8C 9C 2C 3C 4C
(7)Full House:
Three cards of the same value, with the remaining two cards forming a pair. Ranked by the value of the three cards.For example:8C 8D 8H 3S 3H
(8)Four of a Kind:
Four cards with the same value. Ranked by the value of the four cards.For example:8C 8D 8H 8S 4H
(9)Straight Flush:
Five cards of the same suit with consecutive values. Ranked by the highest card in the hand.For example:2C 3C 4C 5C 6C
Your job is to compare several pairs of poker hands and to indicate which, if either, has a higher rank.

输入

The input file contains several lines, each containing the designation of ten cards: the first five cards are the hand for the player named "Black" and the next five cards are the hand for the player named "White".

输出

For each line of input, print a line containing one of the following:
Black wins.
White wins.
Tie.

样例输入

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

样例输出

White wins.
Black wins.
Black wins.
Tie.
这道题其实就是梭哈,但是经过我测试发现其中有一个人(Black或White)手里5张牌都是
一样的情况,譬如Black手里有5个2.....不得不吐槽是个Bug啊....由于本人英文没有那
么好,所以当问老师这个BUG时候他说要求里说了5个一样的就看成四条带一个...
接下来上代码,我写的比较繁琐,写的差不多了才想到用结构体,懒得改了,如果有朋友
能耐心看这个代码可以改成结构体


上代码了~

#include <stdio.h>
#include<string.h>
#define MAXN_P 29+1
#define MAXN_N 10 + 1
#define MAXN_A 5
#define MAXN_WH 4
char pok[MAXN_P];//全部扑克
/*例如:
8H 7H 6H 5H 4H
a[]={4,5,6,7,8}//a是自己手牌除了从小到大排序没做别的变化
b[]={4,5,6,7,8}//b是在a基础上把手牌一样的重合只显示一个例如8,8只显示一个8,其余的从0开始用0站位,同时按d的顺序进行一一对应排列
c[]={0,0,5,0}//c是CDHS四个花色的个数
d[]={1,1,1,1,1}//d是与b一一对应,显示b的每个对应位置的牌的个数
再例:
8H 9H 7H 8C 7C
a[]={7,7,8,8,9}
b[]={0,0,7,8,9}
c[]={2,0,3,0}
d[]={0,0,2,2,1}
*/
void score(int a[], int b[],int c[],int d[], int *s)
{
    memset(d,0,5*sizeof(int));
    memset(b,0,5*sizeof(int));
    int i, j, temp;
    j = 3;
    b[4] = a[4];
    for(i = 3; i >= 0; i--){//b把a中相同数字重合然后小到大排序前面用0站位,生成b
        if(a[i] != a[i+1]){
            b[j] = a[i];
            j--;
        }
    }
    //for(i = 0; i < 5; i++)printf("%d ", b[i]);
    j = 4;
    d[4] = 1;
    for(i = 3; i >= 0; i--){// d:与b一一对应关系,为b中对应位置的数字个数
        if(a[i] == a[i+1]){
            d[j]++;
            continue;
        }
        j--;
        d[j]++;
    }
    for(i = 0; i < 4; i++){
        for(j = i+1; j < 5; j++){//按d排序小到大,顺便把b顺序也按d变了,同时如果两个d相等则两者同时按对应位置b的大小进行互换
            if(d[i] > d[j]){
                temp = d[i];
                d[i] = d[j];
                d[j] = temp;
                temp = b[i];
                b[i] = b[j];
                b[j] = temp;
            }
            else if(d[i] == d[j]){
                if(b[i]>b[j]){
                    temp = b[i];
                    b[i] = b[j];
                    b[j] = temp;
                }
            }
        }
    }
    /*这步(按d排序小到大,顺便把b顺序也按d变了)是如例子2变成了
    8H 9H 7H 8C 7C
    a[]={7,7,8,8,9}
    b[]={0,0,7,8,9}
    c[]={2,0,3,0}
    d[]={0,0,2,2,1}
    b'[]={0,0,9,7,8}
    d'[]={0,0,1,2,2}
    */
    if(d[0] ==1&& d[1] ==1&& d[2] ==1&& d[3] ==1&& d[4] ==1){
        if(b[4]-b[3]==1&&b[3]-b[2]==1&&b[2]-b[1]==1&&b[1]-b[0]==1&&(c[3] == 5||c[0] == 5 || c[1]==5 ||c[2]==5)) *s = 9;
        else if(b[4]-b[3]==1&&b[3]-b[2]==1&&b[2]-b[1]==1&&b[1]-b[0]==1&&c[3]!=5)    *s = 5;
        else if(c[3] == 5||c[0] == 5 || c[1]==5 ||c[2]==5)  *s = 6;
        else   
            *s = 1;
    }
    else if(d[4] == 2 && d[3] == 1) *s = 2;
    else if(d[4] == 2 && d[3] == 2) {
        *s = 3;
    }
    else if(d[4] == 3 && d[3]==1)   *s = 4;
    //else if(c[3] == 5)    *s = 6;
    else if(d[4] == 3 && d[3] == 2) *s = 7;
    else if(d[4] == 4||d[4]==5) *s = 8;
    //分数确定完毕
 
}
void main()
{
    int i, j, s_b, s_w, temp;
    while(gets(pok) != NULL){
        j = 0;
        int wc[MAXN_A] = {0};
        int bc[MAXN_A] = {0};
        int ge_w[MAXN_A] = {0};
        int ge_b[MAXN_A] = {0};
        int pok_n[MAXN_A] = {0};//每相同张牌的个数,从大到小排序
        int bh[MAXN_WH] = {0};// black 的花色
        int wh[MAXN_WH] = {0};// white 的花色
        int b[MAXN_A] = {0};//black 5张的牌
        int w[MAXN_A] = {0};//white 5张的牌
        for(i = 0; i < 13; i += 3){//black 5张的牌
            if(pok[i] >= 50 && pok[i] <= 57)
                b[j] = pok[i] - 48;
            else if(pok[i] == 'T')  b[j] = 10;
            else if(pok[i] == 'J')  b[j] = 11;
            else if(pok[i] == 'Q')  b[j] = 12;
            else if(pok[i] == 'K')  b[j] = 13;
            else if(pok[i] == 'A')  b[j] = 14;
            j++;
        }
 
        j = 0;
 
        for(i = 15; i < 29; i += 3){//white 5张牌
            if(pok[i] >= 50 && pok[i] <= 57)
                w[j] = pok[i] - 48;
            else if(pok[i] == 'T')  w[j] = 10;
            else if(pok[i] == 'J')  w[j] = 11;
            else if(pok[i] == 'Q')  w[j] = 12;
            else if(pok[i] == 'K')  w[j] = 13;
            else if(pok[i] == 'A')  w[j] = 14;
            j++;
        }
 
        for(i = 1; i < 14; i += 3){// black 的花色
            if(pok[i] == 'C')   bh[0]++;
            else if(pok[i] == 'D')  bh[1]++;
            else if(pok[i] == 'H')  bh[2]++;
            else if(pok[i] == 'S')  bh[3]++;
        }
        for(i = 16; i < 29; i += 3){// white 的花色
            if(pok[i] == 'C')   wh[0]++;
            else if(pok[i] == 'D')  wh[1]++;
            else if(pok[i] == 'H')  wh[2]++;
            else if(pok[i] == 'S')  wh[3]++;
        }
        for(i = 0; i < 4; i++){//给b  w  的牌按从小到大排序
            for(j = i+1; j < 5; j++){
                if(b[i] > b[j]){
                    temp = b[i];
                    b[i] = b[j];
                    b[j] = temp;
                }
                if(w[i] > w[j]){
                    temp = w[i];
                    w[i] = w[j];
                    w[j] = temp;
                }
            }
        }
        //for(i = 0; i < 5; i++)printf("%d\n", b[i]);
        score(b, bc, bh, ge_b, &s_b);
        score(w, wc, wh, ge_w, &s_w);
        //printf("%d\n%d\n",sco_b,sco_w);
        if(s_b > s_w)
            printf("Black wins.\n");
        if(s_w > s_b)
            printf("White wins.\n");
        if(s_b == s_w){
            for(i = 4; i >=0; i--){
                //printf("%d %d\n", bc[i], wc[i]);
                if(bc[i] > wc[i]){
                    printf("Black wins.\n");
                    break;
                }
                if(bc[i] < wc[i]){
                    printf("White wins.\n");
                    break;
                }
            }
        }
 
        if(i == -1) printf("Tie.\n");
        /*for(i = 0;i<5;i++)printf("%d ", b[i]);printf("\n");
        for(i = 0;i<5;i++)printf("%d ", w[i]);printf("\n");
        for(i = 0;i<5;i++)printf("%d ", bc[i]);printf("\n");
        for(i = 0;i<5;i++)printf("%d ", wc[i]);printf("\n");
        for(i = 0;i<4;i++)printf("%d ", bh[i]);printf("\n");
        for(i = 0;i<4;i++)printf("%d ", wh[i]);printf("\n");
        for(i = 0;i<5;i++)printf("%d ", ge_b[i]);printf("\n");
        for(i = 0;i<5;i++)printf("%d ", ge_w[i]);printf("\n");
        printf("%d %d\n",s_b,s_w);*/
    }
}
 
/**************************************************************
    Problem: 2176
    User: 2012014425
    Language: C
    Result: 正确
    Time:16 ms
    Memory:768 kb
****************************************************************/


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ACM: Poker Game 的相关文章

  • 是否有与 posix_memalign 对应的 C++ 版本?

    当我打电话时posix memalign http man7 org linux man pages man3 posix memalign 3 html为类型的对象分配对齐的内存Foo在我的 C 代码中 我需要做一个reinterpret
  • CLR 2.0 与 4.0 性能比较?

    如果在 CLR 4 0 下运行 为 CLR 2 0 编译的 NET 程序会运行得更快吗 应用程序配置
  • 使用 C# 登录《我的世界》

    我正在尝试为自己和一些朋友创建一个简单的自定义 Minecraft 启动器 我不需要启动 Minecraft 的代码 只需要登录的实际代码行 例如 据我所知 您过去可以使用 string netResponse httpGET https
  • IdentityServer 4 对它的工作原理感到困惑

    我阅读和观看了很多有关 Identity Server 4 的内容 但我仍然对它有点困惑 因为似乎有很多移动部件 我现在明白这是一个单独的项目 它处理用户身份验证 我仍然不明白的是用户如何注册它 谁存储用户名 密码 我打算进行此设置 Rea
  • 如何在C(Linux)中的while循环中准确地睡眠?

    在 C 代码 Linux 操作系统 中 我需要在 while 循环内准确地休眠 比如说 10000 微秒 1000 次 我尝试过usleep nanosleep select pselect和其他一些方法 但没有成功 一旦大约 50 次 它
  • 查找进程的完整路径

    我已经编写了 C 控制台应用程序 当我启动应用程序时 不使用cmd 我可以看到它列在任务管理器的进程列表中 现在我需要编写另一个应用程序 在其中我需要查找以前的应用程序是否正在运行 我知道应用程序名称和路径 所以我已将管理对象搜索器查询写入
  • 函数参数的默认参数是否被视为该参数的初始值设定项?

    假设我有这样的函数声明 static const int R 0 static const int I 0 void f const int r R void g int i I 根据 dcl fct default 1 如果在参数声明中指
  • File.AppendText 尝试写入错误的位置

    我有一个 C 控制台应用程序 它作为 Windows 任务计划程序中的计划任务运行 此控制台应用程序写入日志文件 该日志文件在调试模式下运行时会创建并写入应用程序文件夹本身内的文件 但是 当它在任务计划程序中运行时 它会抛出一个错误 指出访
  • 使用 LINQ to SQL 时避免连接超时的最佳实践

    我需要知道在 net 应用程序中使用 LINQ to SQL 时避免连接超时的最佳实践 特别是在返回时IQueryable
  • 在Linux中,找不到框架“.NETFramework,Version=v4.5”的参考程序集

    我已经设置了 Visual studio 来在我的 Ubuntu 机器上编译 C 代码 我将工作区 我的代码加载到 VS 我可以看到以下错误 The reference assemblies for framework NETFramewo
  • 为什么可以通过ref参数修改readonly字段?

    考虑 class Foo private readonly string value public Foo Bar ref value private void Bar ref string value value hello world
  • 打破 ReadFile() 阻塞 - 命名管道 (Windows API)

    为了简化 这是一种命名管道服务器正在等待命名管道客户端写入管道的情况 使用 WriteFile 阻塞的 Windows API 是 ReadFile 服务器已创建启用阻塞的同步管道 无重叠 I O 客户端已连接 现在服务器正在等待一些数据
  • IQueryable 单元或集成测试

    我有一个 Web api 并且公开了一个端点 如下所示 api 假期 name name 这是 Web api 的控制器 get 方法 public IQueryable
  • C++ int 前面加 0 会改变整个值

    我有一个非常奇怪的问题 如果我像这样声明一个 int int time 0110 然后将其显示到控制台返回的值为72 但是当我删除前面的 0 时int time 110 然后控制台显示110正如预期的那样 我想知道两件事 首先 为什么它在
  • 检测到严重错误 c0000374 - C++ dll 将已分配内存的指针返回到 C#

    我有一个 c dll 它为我的主 c 应用程序提供一些功能 在这里 我尝试读取一个文件 将其加载到内存 然后返回一些信息 例如加载数据的指针和内存块的计数到 c Dll 成功将文件读取到内存 但在返回主应用程序时 程序由于堆损坏而崩溃 检测
  • WebBrowser.Print() 等待完成。 。网

    我在 VB NET 中使用 WebBrowser 控件并调用 Print 方法 我正在使用 PDF 打印机进行打印 当调用 Print 时 它不会立即启动 它会等到完成整个子或块的运行代码 我需要确保我正在打印的文件也完整并继续处理该文件
  • String.Empty 与 "" [重复]

    这个问题在这里已经有答案了 可能的重复 String Empty 和 有什么区别 https stackoverflow com questions 151472 what is the difference between string
  • 这个可变参数模板示例有什么问题?

    基类是 include
  • 使用 C 在 OS X 中获取其他进程的 argv

    我想获得其他进程的argv 例如ps 我使用的是在 Intel 或 PowerPC 上运行的 Mac OS X 10 4 11 首先 我阅读了 ps 和 man kvm 的代码 然后编写了一些 C 代码 include
  • 如何将十六进制字符串转换为无符号长整型?

    我有以下十六进制值 CString str str T FFF000 如何将其转换为unsigned long 您可以使用strtol作用于常规 C 字符串的函数 它使用指定的基数将字符串转换为 long long l strtol str

随机推荐

  • CUDA 动态链接库与静态链接库

    参考 CUDA C BEST PRACTICES GUIDE chapter 15 PREPARING FOR DEPLOYMENT 关于部署CUDA加速的程序时 往往对CUDA加速的程序编译为动态链接库或者静态链接库 这两者导致的区别是
  • python 8行代码搞定 AES加解密

    python 实现AES加解密相关的知识 可以参考以下文章 python实现AES加密解密 但该文章中 对于加密前数据的补全 及解密后去掉多余数据 由作者自己进行了封装 导致代码较为复杂 实际可以使用库中pad和unpad来解决该问题 而使
  • vue中实现高德地图上打点,并添加点击事件,

    文章目录 1 在地图上打点 并定义 click 事件 2 数据由websocket订阅 后台实时推送 3 实时失效 1 在地图上打点 并定义 click 事件 地图上打点 并定义click事件 param map map对象 param i
  • iviewui中表格控件中render的使用示例

    示例了如何在表格中显示按钮 如何将代码转化为文字 iviewui新版本中 如果内容转化输出时 如果不使用render函数 会显示不正常 老版本不存在这个问题
  • 阿里分布式事务框架-seata源码分析

    详细可参考 AT下流程图 TCC下流程图 基于该流程图可大致了解seata中TC TM RM这3个角色在seata框架中的作用 以及两种模式的优缺点
  • 数学建模常用模型(六):时间序列预测

    数学建模常用模型 六 时间序列预测 时间序列预测是数学建模中的一个重要领域 用于预测时间序列数据中未来的趋势和模式 时间序列预测可以帮助我们了解数据的演变规律 做出合理的决策和规划 这是我自己总结的一些代码和资料 本文中的代码以及参考书籍等
  • 移动Web应用的性能及其未来趋势

    在一篇深入的实质性文章中 某iOS开发公司的老板Drew Crawford表示他认为目前移动Web应用运行迟缓 而且并不指望能在不久的将来看到重大改善 并列出了以上观点的全部原因 该文章是此前某篇博客文章的后续之作 在那篇文章中 他指出 与
  • el-select 点击输入框不弹出选项的下拉框

    el select 点击输入框不弹出选项的下拉框 重点是绑定click事件 用它的event判断点击的是输入框还是下拉箭头 如果是输入框 就让它失去焦点 就不会弹出选项的下拉框
  • JSTL在JSP页面上的使用

    1 JSTL标准标签库 JSTL JSP标准标签库 JSTL 是一个JSP标签集合 它封装了JSP应用的通用核心功能 JSTL支持通用的 结构化的任务 比如迭代 条件判断 XML文档操作 国际化标签 SQL标签 除了这些 它还提供了一个框架
  • QNX的应用移植迁移到Linux

    如果你认为本系列文章对你有所帮助 请大家有钱的捧个钱场 点击此处赞助 赞助额1元起步 多少随意 author 锋影 e mail 174176320 qq com 近年来许多嵌入式产品将是公司从自营到开放源代码平台为他们提供更多灵活性和成本
  • 基于微信小程序的manster云音乐小程序

    代码地址 https gitee com manster1231 master cloud music 介绍 基于网易云音乐真实接口开发的音乐小程序 软件架构 Nodejs作为后端 跨站请求伪造 CSRF 伪造请求头 调用官方 API 网易
  • 基于TCP的服务器端/客户端

    TCP服务器端默认函数调用顺序 socket 创建socket bind 分配socket地址 listen 等待连接请求状态 accept 允许连接 read write 数据交换 close 断开连接 等待连接请求状态 int list
  • 数据挖掘-数据清理-噪声数据

    数据清理 噪声数据 数据清理例程试图填充缺失的值 光滑噪声并识别离群点 纠正数据中的不一致 噪声数据 噪声 noise 是被测量的变量的随机误差或方差 光滑数据 去除噪声方法如下 1 分箱 binning 分箱方法通过考察数据的近邻 即周围
  • Linux内核中断之获取中断号

    目录 一 调用流程 二 应用举例 1 查找中断号 2 dts配置 3 驱动函数 Linux内核中可使用platform get irq 函数获取dts文件中设置的中断号 函数原型 int platform get irq struct pl
  • 保姆级Pythpn连载讲义:第五篇注释相关

    注释 目标 注释的作用 单行注释 行注释 多行注释 块注释 01 注释的作用 使用用自己熟悉的语言 在程序中对某些代码进行标注说明 增强程序的可读性 外链图片转存失败 源站可能有防盗链机制 建议将图片保存下来直接上传 img caIBaVK
  • 2012,这一年我该做些啥

    这一年 我应该完成2011年没有完成的事情 让自己在2012没有遗憾 这一年 我应该想想未来的路 给自己一个职业规划 这一年 我应该提升一下自己的技术 让自己更加专业 这一年 我应该提升一下自己的思想 让自己的头脑更加丰富 这一年 我应该养
  • 元素出栈、入栈顺序的合法性(判断一个字符串是否按照出栈顺序)

    假设入栈的序列 1 2 3 4 5 出栈序列为 4 5 3 2 1 判断出栈序列是否合法 实现思路 总的来说就是模拟元素的出入栈过程 并进行判断 首先 判断出栈序列和入栈序列的元素个数是否相等 若不相等 则不合法 若相等 则继续进行判断 其
  • pyqt 打开并显示excel表单

    参考链接 Python PyQt5 图形可视化界面 7 打开表格并显示内容 简书 from PyQt5 import QtCore QtGui QtWidgets from PyQt5 QtGui import QIcon from PyQ
  • GitLab SAST:如何将Klocwork与GitLab一起使用

    GitLab SAST是GitLab和Klocwork的结合 GitLab是一种覆盖了整个DevOps生命周期的集成解决方案 Klocwork是一个静态代码分析和应用安全静态测试 SAST 工具 当将这两个工具一起使用时 可以为软件开发团队
  • ACM: Poker Game

    题目描述 A poker deck contains 52 cards Each card has a suit of either clubs diamonds hearts or spades denoted C D H S in th