首页
编程星球
啊哈磊的小伙伴
求助
交流
添柴
挑战
题库
院校合作
加入圈子
扫码关注啊哈磊
QQ群:703568346
@啊哈编程星球
暑期课程
金牌教练带你玩转编程!
扫码预约课程
未登录
我的添柴
退出账号
搜索
搜索
本版
文章
帖子
用户
啊哈磊_编程从这里起步
»
交流
›
互助分享
›
学习求助
›
各位大神帮帮忙!
返回列表
发新帖
查看:
166
|
回复:
1
各位大神帮帮忙!
[复制链接]
香帅
香帅
当前离线
积分
11
电梯直达
楼主
楼主
|
发表于 2019-3-31 14:45:28
|
只看该作者
|
倒序浏览
|
阅读模式
5
啊哈币
#include <stdio.h>
struct queue
{
int data[1100];
int head;
int tail;
};
struct stack
{
int data[10];
int top;
};
int mian()
{
struct queue q1,q2;
struct stack s;
int book[10];
int i,t;
//初始队列化
q1.head=1;q1.tail=1;
q2.head=1;q2.tail=1;
//初始化栈
s.top=0;
//初始化用来标记的数组,用来标记哪些牌已经在桌上
for(i=1;i<=9;i++)
book[i]=0;
//依次向队插入6个数
//小哼在手上的6张牌
for(i=1;i<=6;i++)
{
scanf("%d",&q1.data[q1.tail]);
q1.tail++;
}
//小哈手上的6张牌
for(i=1;i<=6;i++)
{
scanf("%d",&q2.data[q2.tail]);
q2.tail++;
}
while(q1.head<q1.tail && q2.head<q2.tail )
{
t=q1.data[q1.head];//小哼出一张牌
//判断小哼当前打出的牌是否能赢牌
if(book[t]==0)//表明桌上没有牌面为t的牌
{
//小哼此轮没有赢
q1.head++;//小哼已经打出一张牌,所以要把打出的牌出队
s.top++;
s.data[s.top]=t;//再把打出的牌放到桌上,即入栈
book[t]=1;
}
else
{
q1.head++;
q1.data[q1.tail]=t;
q1.tail++;
while(s.data[s.top]=!t)
{
book[s.data[s.top]]=0;
q1.data[q1.tail]=s.data[s.top];
q1.tail++;
s.top--;
}
book[s.data[s.top]]=0;
q1.data[q1.tail]=s.data[s.top];
q1.tail++;
s.top--;
}
if(q1.head==q1.tail)
{
break;
}
t=q2.data[q2.head];
if(book[t]==0)
{
q2.head++;
s.top++;
s.data[s.top]=t;
book[t]=1;
}
else
{
q2.head++;
q2.data[q2.tail]=t;
q2.tail++;
while(s.data[s.top]=!t)
{
book[s.data[s.top]]=0;
q2.data[q2.tail]=s.data[s.top];
q2.tail++;
s.top--;
}
book[s.data[s.top]]=0;
q2.data[q2.tail]=s.data[s.top];
q2.tail++;
s.top--;
}
}
if(q2.head==q2.tail)
{
printf("小哼wim");
printf("小哼当前手中的牌是");
for(i=q1.head;i<=q1.tail-1;i++)
printf(" %d",q1.data[i]);
if(s.top>0)
{
printf("桌上的牌是");
for(i=1;i<=s.top;i++)
printf("%d",s.data[i]);
}
else
printf("桌上已经没有牌了");
}
else
{
printf("小哈wim");
printf("小哈当前手中的牌是");
for(i=q2.head;i<=q2.tail-1;i++)
printf(" %d",q2.data[i]);
if(s.top>0)
{
printf("桌上的牌是");
for(i=1;i<=s.top;i++)
printf("%d",s.data[i]);
}
else
printf("桌上已经没有牌了");
}
getchar();getchar();
return 0;
}
复制代码
我来回答
收藏
0
转播
分享
回复
举报
香帅
香帅
当前离线
积分
11
沙发
楼主
|
发表于 2019-3-31 17:40:53
|
只看该作者
谢谢,已经找到问题了
回复
举报
返回列表
发新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖并转播
回帖后跳转到最后一页
广播台
特别关注
快速回复
返回顶部
返回列表