永发信息网

54张扑克牌,留5张底牌,其它分给四个人,求代码?实现我图片上的内容

答案:5  悬赏:30  手机版
解决时间 2021-11-27 17:35
54张扑克牌,留5张底牌,其它分给四个人,求代码?实现我图片上的内容
最佳答案
#include 
#include 
#include 

const int MAXSIZE = (54 - 6)/4; // 六张底牌
const int PLAYERS = 4;
const char WAY[PLAYERS][4] = {"东","南","西","北"};
const char type[6][5] = {"梅花","方片","红桃","黑桃","小王","大王"};
const char point[] = "JQKA";

typedef struct card {
int type; //  type 0:梅花,1:方片,2:红桃,3:黑桃,4:王
int point; // type = 0 -- 3时,point = 2 -- 14,type = 4时,point = 0 -- 1 
}CARD;

void sort(CARD a[],int n) {
int i,j,k;
CARD t;
for(i = 0; i < n - 1; ++i) {
k = i;
for(j = i + 1; j < n; ++j) {
if(a[k].type < a[j].type) k = j;
}
if(k != i) {
t = a[k];
a[k] = a[i];
a[i] = t;
}
}
}

void show(CARD a[],int n) {
int i,newtype = 4,oldtype = 0;
for(i = 0; i < n; ++i) {
newtype = a[i].type;
if(newtype != oldtype) {
printf("
");
if(a[i].type >= 0 && a[i].type <= 3)
printf("%s: ",type[a[i].type]);
else printf("王牌: ");
oldtype = newtype;
}
if(a[i].type >= 4) printf("%s ",type[a[i].point - 11]);
else if(a[i].point < 11) printf("%d ",a[i].point);
else printf("%c ",point[a[i].point - 11]);
}
printf("

");
}

int Has(CARD a[][MAXSIZE],int b[],int n,CARD card) {
int i,j;
for(i = 0; i < n; ++i) {
for(j = 0; j < b[i]; ++j) {
if(a[i][j].type == card.type && a[i][j].point == card.point)
return 1;
}
}
return 0;
}

int main() {
CARD player[PLAYERS][MAXSIZE],t;
int i = 0,who,number[PLAYERS] = {0};
srand((unsigned)time(NULL));
while(i < 4 * MAXSIZE) {
who = rand()%4; // 随机选择牌手
t.type = rand()%5; // 随机选择花色
if(t.type == 4) t.point = rand()%2 + 15; // 大小王
else t.point = rand()%13 + 2; // 其他四种花色
if(!Has(player,number,PLAYERS,t)) {
while(number[who] == MAXSIZE)
who = (who + 1)%PLAYERS;
player[who][number[who]] = t;
++number[who];
++i;
}
}
for(i = 0; i < PLAYERS; ++i) {
sort(player[i],MAXSIZE);
printf("%s:",WAY[i]);
show(player[i],MAXSIZE);
}
return 0;
}
全部回答
54-5=49 怎么平均分给四个人?
C语言么
Simon意思

我这里有个模拟发牌52张的代码,稍微改改就可以了,供你参考

#include  
#include 
#include 
int main(void)

int aim,i;
int poker[52]={0};

srand((unsigned)time(NULL)); 


aim = rand()%52;  





for(i=1;i <= 52; i++)
{
aim = rand()%52;

while(poker[aim] == 1)
{
aim = rand()%52;
}
poker[aim] = 1;

printf(" 第 %2d张牌:",i);
switch(aim/13)
{
case 0:
printf("梅花 ");
break;
case 1:
printf("方块 ");
break;
case 2:
printf("红桃 ");
break;
case 3:
printf("黑桃 ");
break;
default:break;
}
switch(aim%13+1)
{
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
printf("%2d",aim%13+1);
break;
case 1:
printf(" A");
break;
case 11:
printf(" J");
break;
case 12:
printf(" Q");
break;
case 13:
printf(" K");
break;
default:break;
}
}
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
研祥集团的研祥大事记
CPU G1610 @ 2.60GHz支持64位win7旗舰版
B证怎样增驾A2证
有五个感官描写你最喜欢的食物
虽然有很多顾及,但我还是很爱你。男朋友说的
c项,不定积分,不用加c吗?
努丽美容沙龙地址在哪,我要去那里办事,
2014年度内蒙古自治区城镇居民人均可支配收入
昨天早上徐家小区按摩死人
新莽荒纪装备怎么获取 新莽荒纪装备系统详解
usb延长分线器和usb延长线哪个好用
从长春火车站到长春荣德光学有限公司做哪路公
单选题在相同条件下,由等体积的H2、N2、CO2
女士鞋码235是多大
女子隐瞒史与男子交往怀孕
推荐资讯
各位大神为什么4平方的铜电线价格相差那么大
乌拉特前旗气象局地址在什么地方,想过去办事
170. Believe in yourself and be you are.A
天水至五明佛学院路线
水产门市部对联
水体污染的危害是多方面的,它不仅加剧水资源
哪个是解压
do whice like you one
熊仔头<失忆女友>的背景音乐是什么歌
杯莫停土菜馆在什么地方啊,我要过去处理事情
走常州火车站到林家唐有几路车
一个季度有几天?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?