poker

2023-05-16

#include<stdbool.h>
#include<stdio.h>
#include<stdlib.h>


#define NUM_RANKS 13
#define NUM_SUTTS 4
#define NUM_CARDS 5




/*prototypes*/
void read_cards(int num_in_rank[],int num_in_suit[]);
void analyze_hand(int num_in_rank[],int num_in_suit[],bool*straight,bool*flush,bool*four,bool*three,int*pairs);
void print_result(bool straight,bool flush,bool four,bool three,int pairs);


/************************************************************
 * main:Calls read_cards,analyze_hand,and print_result      *
 *      repeatedly.                                         *
 ***********************************************************/
int main(void)
{
int num_in_rank[NUM_RANKS];
int num_in_suit[NUM_SUTTS];
bool straight,flush,four,three;
int pairs;


for(;;){
read_cards(num_in_rank,num_in_suit);
analyze_hand(num_in_rank,num_in_suit,&straight,&flush,&four,&three,&pairs);
print_result(straight,flush,four,three,pairs);


}
}
/************************************************************
 * read_cards:Read the cards into the external              *
 *            Variables num_in_rank and num_in_suit;        *
 *            checks for bad cards and duplicates cards.    *
 ***********************************************************/
void read_cards(int num_in_rank[NUM_RANKS],int num_in_suit[NUM_SUTTS])
{
bool card_exists[NUM_RANKS][NUM_SUTTS];
char ch,rank_ch,suit_ch;
int rank ,suit;
bool bad_card;
int cards_read=0;


for(rank=0;rank<NUM_RANKS;rank++){
num_in_rank[rank]=0;
for(suit=0;suit<NUM_SUTTS;suit++)
card_exists[rank][suit]=false;
}
for(suit=0;suit<NUM_SUTTS;suit++)
num_in_suit[suit]=0;


while(cards_read<NUM_CARDS){
bad_card=false;


printf("Enter a card:");


rank_ch=getchar();
switch(rank_ch){
case'0':          exit(EXIT_SUCCESS);
case'2':          rank=0;break;
case'3':          rank=1;break;
case'4':          rank=2;break;
case'5':          rank=3;break;
case'6':          rank=4;break;
case'7':          rank=5;break;
case'8':          rank=6;break;
case'9':          rank=7;break;
case't':case'T':  rank=8;break;
case'j':case'J':  rank=9;break;
case'q':case'Q':  rank=10;break;
case'k':case'K':  rank=11;break;
case'a':case'A':  rank=12;break;
default:          bad_card=true;


}


suit_ch=getchar();
switch(suit_ch){
case'c':case'C':suit=0;break;
case'd':case'D':suit=1;break;
case'h':case'H':suit=2;break;
case's':case'S':suit=3;break;
default:          bad_card=true;
}


while((ch=getchar())!='\n')
if (ch != ' ') bad_card = true;


if(bad_card)
printf("Bad card;ignore.\n");
else if(card_exists[rank][suit])
printf("Duplicate card;ignored.\n");
else{
  num_in_rank[rank]++;
num_in_suit[suit]++;
card_exists[rank][suit]=true;
cards_read++;
}


}
}


/************************************************************
* analyze_hand:Determines whether the hand contains a       *
*              straight ,a flush,four-of-a-kind,                                       *
*              and/or three-of-a-kind;determines the                *
*              number of pairs;stores the results into      *
*              the external variables straight,flush,       *
*              four,three,and pairs.                        *
************************************************************/


void analyze_hand(int num_in_rank[NUM_RANKS],int num_in_suit[NUM_SUTTS],bool*straight,bool*flush,bool*four,bool*three,int*pairs)
{
int num_consec=0;
int rank,suit;


*straight=false;
*flush=false;
*four=false;
*three=false;
*pairs=0;


/*check for flush*/
for (suit=0;suit<NUM_SUTTS;suit++)
if(num_in_suit[suit]==NUM_CARDS)
*flush=true;


/*check for straight*/
rank=0;
while(num_in_rank[rank]==0)rank++;
for(;rank<NUM_RANKS&&num_in_rank[rank]>0;rank++)
num_consec++;
if(num_consec==NUM_CARDS){
*straight=true;
return ;
}


/*check for 4-of-a-kind,3-of-a-kind,and pairs*/
for(rank=0;rank<NUM_RANKS;rank++){
if(num_in_rank[rank]==4)*four=true;
if(num_in_rank[rank]==3)*three=true;
if(num_in_rank[rank]==2)(*pairs)++;
}
}
/************************************************************
* print_reslut:prints the classification of the hand,       *
*              based on the values of the external          *
*              variable straight,flush,four, three,         *
*              and pairs                                    *
************************************************************/






void print_result(bool straight,bool flush,bool four,bool three,int pairs)
{
if(straight&&flush)printf("Straight flush");
else if(four)      printf("Four of a kind");
else if(three&&pairs==1)printf("Full house");
else if(flush)     printf("Flush");
else if(straight)  printf("Straight");
else if(three)     printf("Three of a kind");
else if(pairs==2)  printf("Two pairs");
else if(pairs==1)  printf("Pair");
else               printf("High card");


printf("\n\n");






}

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

poker 的相关文章

  • pandas学习之df.rename()

    pandas学习之df rename df rename 用于更改行列的标签 xff0c 即行列的索引 可以传入一个字典或者一个函数 在数据预处理中 xff0c 比较常用 官方文档 xff1a DataFrame rename self m
  • java8操作两个集合List

    public static void main String args List lt String gt list1 61 new ArrayList lt String gt list1 add 34 1 34 list1 add 34
  • Atcoder AGC005 题解

    A STring 用类似括号匹配的方法搞一下即可 span class token macro property span class token directive keyword include span span class toke
  • CentOS-7安装桌面环境

    CentOS 7安装桌面环境 CentOS 7安装桌面环境 CentOS 7安装Server with GUI 设置为开机从桌面环境启动 yum y group install 39 Server with GUI 39 systemctl
  • [软件注册]Sublime 3 激活/注册码(key)

    偶然发现了一种sublime激活方式 使用的sublime3 1 1版本 亲试有效 Step1 配置 host文件 推荐使用 switchhost软件 可以快速变更host span class hljs number 127 0 span
  • 测试git能否连接github

    welcome to my blog 使用以下命令进行测试 ssh T git 64 github com 出现报错 ssh dispatch run fatal Connection to 13 250 177 223 port 22 S
  • vtk中实现3D模型(读取文件)

    xff08 xff09 VTK 坐标系统及空间变换 窗口 视图分割 mb5fed73533dfa9的技术博客 51CTO博客 VTK学习 xff08 三 xff09 VTK读取序列图像 灰信网 xff08 软件开发博客聚合 xff09 读取
  • centos中安装Python2.7

    转载于 xff1a 秋水逸冰 CentOS 6 8安装Python2 7 13 查看当前系统中的 Python 版本 python version 返回 Python 2 6 6 为正常 检查 CentOS 版本 cat etc redha
  • 安装tar.gz文件(无configure文件)

    如何安装tar gz文件 xff08 以webstorm为例 xff09 1 获取root权限并输入密码 xff1a su root 2 进入有该文件的目录下 xff08 以我的为例 xff0c 具体看你的文件在哪里 xff09 cd 下载
  • 游戏服务端框架之业务线程模型

    请求消息绑定线程策略的选择 在上一篇文章中 我们看到 消息是直接在网络框架的io线程中处理的 这样做有一个非常严重的缺陷 如果业务处理比较耗时 那么io线程接受消息的速度就会下降 严重影响io的吞吐量 典型的 我们应该另起线程池 专门用于异
  • 在WSL中使用GPU:WSL2 + Ubuntu 18.04 + CUDA + Gnome图形界面环境配置

    目录 引言1 确认Windows 10版本2 在Windows上安装WSL23 在Windows上安装CUDA on WSL驱动4 在WSL2中安装CUDA Toolkit3 测试CUDA是否能在WSL2中运作4 安装Gnome图形界面其他
  • Centos 开启路由转发实现全网互通

    只需在RouterSrv网关服务器上开启路由转发功能即可 root 64 RouterSrv vi etc sysctl conf net ipv4 ip forward 61 1 添加此行即可 root 64 localhost sysc

随机推荐

  • 虚拟机中配置外网环境

    文章目录 在虚拟机中配置外网环境 在虚拟机中配置外网环境 主机为 win10 xff0c 虚拟机中为 ubuntu 系统 xff0c 采用clash 1 xff0c 设置 Allow Lan xff0c 允许局域网访问 2 xff0c 虚拟
  • mysql 操作数据库(备份与恢复)

    一 直接把创建数据库的语句放到sql 文件中 xff1a php 写法 xff1a lt php mysql port 61 get mysql port cmd 61 US MYSQL BIN 34 mysql exe port 61 3
  • Go调用Python by go-python3

    确保python版本为3 7 conda create go python span class token assign left variable python span span class token operator 61 spa
  • linux下搭建maven私服

    maven私服我相信很多公司都有 xff0c 私服的好处有以下几点 xff1a 1 节省下载资源开销 jar包 xff08 不一定是jar xff0c 也可以是其他资源 xff09 都存在私服 xff0c 可以不必每次下载都去远程仓库去下载
  • git 安装包 最新 下载 快速 国内 镜像 地址

    下载git时 xff0c 先进官网看 https git scm com download win 然后发现几kb的网速 xff0c 这是要让我下一年么 xff0c 找了找网上有没有其他的镜像 xff0c 发现阿里有一个镜像 xff0c 下
  • docker笔记(四、docker部署beego打包后的二进制文件)

    在beego工程里 xff0c 使用go build可以将该工程打包成一个二进制文件 xff0c 那么这个二进制文件在docker里面该怎么部署呢 xff1f 先写一个简单的图片上传的demo xff0c 名字叫docker test 在工
  • LINUX服务器最简洁的HTTPS免费证书配置方法

    注意 xff1a 该方法已在多台服务器配置了免费的https证书 xff0c 无论是更新还是第一次配置都运行成功 xff1b 由于是免费版 xff0c 每个证书都只有三个月的有效期 xff0c 也无法保证安全和稳定性 xff0c 所以只建议
  • 【性能测试】获取性能系统指标之示例Python代码

    usr bin env python coding utf 8 import sys import datetime import time import psutil from ctypes import 34 34 34 性能测试示例P
  • select I/O 多路复用实现服务器聊天室功能

    基本概念 IO多路复用是指内核一旦发现进程指定的一个或者多个IO条件准备读取 xff0c 它就通知该进程 IO多路复用适用如下场合 xff1a xff08 1 xff09 当客户处理多个描述字时 xff08 一般是交互式输入和网络套接口 x
  • iOS-使用Masnory实现UITableViewCell自适应高度

    在iOS开发当中 xff0c 如果涉及到UITableViewCell的一些复杂UI的绘制时难免会碰到这么一个难题 xff1a UITableViewCell的高度如何设置 xff01 的确 xff0c 我们就拿一个简单的例子来说 xff1
  • ubuntu中共享文件夹看不到

    博主的ubuntu安装VMwaretools后共享文件夹设置完发现在 mnt hgfs总看不到 经过多次摸索后终于可以了 首先要使用root用户登陆ubuntu 然后再安装VMwaretools 在设置共享文件夹 然后解决挂在的问题 1 设
  • keystore was tampered with,or password was incorrect解决办法

    利用keytool导入证书 xff0c 命令如下 keytool import alias HZZSQKJdianshang file HZZSQKJdianshang cer keystore trust jks storepass st
  • Convert Picture or Video to ascii

    一个利用ascii拼成的谷歌街景地图 xff01 http tllabs io asciistreetview 看上去效果真不错 xff01 除此之外 xff0c linux下面也有类似的ascii艺术 xff0c 比如 aview asc
  • texlive2015-6安装

    http www cnblogs com snake553 p 4831588 html CentOS6 5 下安装 texlive2015 并设置 ctex 中文套装 0 卸载旧版本的 texlive 0 1 卸载 texlive2007
  • ubuntu20.04 安装显卡驱动后开机卡住,无法进入登陆界面问题解决

    ubuntu20 04 安装显卡驱动后开机卡住 xff0c 无法进入登陆界面问题解决 进入recovery mode 禁用nvidia drm systemctl isolate multi user target modprobe r n
  • Linux环境变量失效,命令不可用

    背景 linux在修改完环境变量 etc profile后保存文件后 xff0c 发现大多数命令不可用 xff0c 只有少数如 xff1a cd pwd可以使用 xff1b 原因分析 1 etc profile文件中有无效字符或变量 xff
  • Ubuntu20.04安装MySQL5.7-实测3种方法(保姆级教程)

    最近生产系统系统需要使用MySQL5 7版本的数据库 xff0c 而Ubuntu20 04默认是8 0的版本 xff0c 折腾了一段时间后 xff0c 测试了3中方法 xff0c 在实际应用环境中测试成功 xff0c 因此发布出来给大家参考
  • 数据仓库的源数据类型

    数据仓库中集成了企业几乎所有的可以获取到的数据以用于数据分析和决策支持 xff0c 当然也包括了我在网站分析的数据来源一文中所提到的所有数据 这些进入到数据仓库中的数据无外乎三种类型 xff1a 结构化数据 半结构化数据 和非结构化数据 x
  • soj 1075 拓扑排序队列实现

    就是soj 拓扑排序的模板题吧 然后我中午把用队列实现的拓扑排序的方法看了下 晚上就打算来练一下这种纯模板 对于这实现的方法 xff0c 我的理解就是存下每个节点的入度以及它指向的其他节点 xff0c 由于指向多少个这个不太能确定所以用一个
  • poker

    include lt stdbool h gt include lt stdio h gt include lt stdlib h gt define NUM RANKS 13 define NUM SUTTS 4 define NUM C