随机取扑克牌中10张牌

编程入门 行业动态 更新时间:2024-10-06 04:07:55

随机取<a href=https://www.elefans.com/category/jswz/34/1766301.html style=扑克牌中10张牌"/>

随机取扑克牌中10张牌

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#define MaxStack 100


int stack[MaxStack];
int top = -1;


int push(int value)
{
if (top>=MaxStack)
{
printf("栈内容全满!\n");
return -1;
}
top++;
stack[top] = value;
}


int pop()
{
int temp;
if (top<0)
{
printf("栈内容是空的!\n");
return -1;
}
temp = stack[top];
top--;
return temp;
}


int empty()
{
if (top == -1)
{
return 1;
}
else
return 0;
}


void main()
{
int card[52];
int pos;
int i,temp;
long temptime;


srand(time(&temptime)%60);
for(i=0;i<52;i++)
card[i] = 0;
i = 0;
while(i != 10)
{
pos = rand()%52;
if (card[pos] == 0)
{
push(pos);
card[pos] = 1;
i++;
}
}
while(!empty())
{
temp = pop();
printf("[%c%2d]",temp/13+3,temp%13+1);
}
printf("\n");
}


结果:


更多推荐

随机取扑克牌中10张牌

本文发布于:2024-03-07 18:02:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718526.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:扑克牌

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!