当前位置:网站首页>C语言实现发牌功能基本方法
C语言实现发牌功能基本方法
2022-07-26 05:07:00 【an520_】
大家好!
今天主要和大家聊一聊,如何利用C语言实现自动发牌程序。
第一:问题描述
一副扑克有52张牌,打桥牌时应将牌分给4个人。请设计一个程序完成自动发牌的工作。要求:黑桃用S (Spaces)表示,红桃用H (Hearts)表示,方块用D (Diamonds)表示,梅花用C (Clubs)表示。
第二:问题分析
思路:
这题实现起来还是比较简单的,只需定义两个多维的字符数组,第一个用来存放扑克的编号,第二个用来存放4个玩家的手牌。
52张牌发给4个人,需要发13轮,每轮按玩家的编号顺序给他们发牌,发牌时,用随机函数生成要发牌的编号(随机函数的介绍可以参考我第61天的练习),如果该牌之前没被发放(已发放的牌用'\0'标记),则将牌的编号存放到玩家的手牌数组中,同时将该牌的编号赋值为'\0'。如果生成的随机数对应的牌已经被发过了,则继续生成新的随机数。当52张牌全部发放完毕,打印发牌的结果。
扑克数组char poker[4][13];中的4表示花色种类有四种,13表示每种有13张(13个编号),扑克牌的编号(名字)用字符表示,分别为:{'2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K', 'A'}('0'表示10)
玩家的手牌数组是一个三维字符数组,char players[PLAYER_NUMBER][4][13] = {0}; (PLAYER_NUMBER是玩家数量,4表示牌的花色种类有4种,13为某种花色的牌最多13张)
初始化时,手牌数组的所有值设置为'\0',表示手上无牌。
第三:代码实现




第四:运行结果

总结:只有多练,在练的过程中,找到问题点逐个解决并总结,才能走的更远。
【学习交流群769843038】
【下方分享一些学习教程资料】:
【下方网盘免费资料包,需要的放心领取】:
嵌入式物联网 stm32 c/c++、QT Linux资料包【华清远见发放资料包】
http://makerschool.mikecrm.com/7ADq4jq

边栏推荐
- webassembly 01基本资料
- JVM第六讲:线上环境 FGC 频繁,如何解决?
- What are the well-known to-do apps at home and abroad
- JVM第二讲:类加载机制
- Improve reduce parallelism in shuffle operation
- 时代潮流-云原生数据库的崛起
- @Autowired注解的原理
- C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希
- I talked with the interviewer about MySQL optimization in five dimensions
- Switch to router technology: OSPF single zone configuration, OSPF multi zone and end zone
猜你喜欢
![[weekly translation go] how to write your first program with go](/img/77/cf77a46340a39797382fd7b60517d5.png)
[weekly translation go] how to write your first program with go

Date and time function of MySQL function summary

An online accident, I suddenly realized the essence of asynchrony

C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希

五个维度着手MySQL的优化,我和面试官都聊嗨了

AQS唤醒线程的时候为什么从后向前遍历,我懂了

How to connect tdengine through idea database management tool?

SAP报表开发步骤

LeetCode链表问题——203.移除链表元素(一题一文学会链表)

Simulation of future air pollution changes
随机推荐
阿里三面:MQ 消息丢失、重复、积压问题,如何解决?
New knowledge in big homework
嵌入式分享合集20
C语言函数
AXI协议(5):AXI协议的burst机制
AXI协议(4):AXI通道上的信号
Mysql主从同步及主从同步延迟解决方案
Mysql优化
你对“happen-before原则”的理解可能是错的?
What are the characteristics of the grammar of Russian documents in the translation of scientific papers
@Principle of Autowired annotation
Application of remote sensing, GIS and GPS technology in hydrology, meteorology, disasters, ecology, environment and health
Nacos registry
unity场景跳转脚本
Switch and router technology: dynamic routing protocol, rip routing protocol and OSPF routing protocol
CMD operation command
ALV程序收集
Interprocess communication
MySQL eight knowledge points: from getting started to deleting the database
Distance between bus stops: simple simulation problem