搜索
查看: 166|回复: 1
打印 上一主题 下一主题

各位大神帮帮忙!

[复制链接]
跳转到指定楼层
楼主
 楼主| 发表于 2019-3-31 14:45:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
  1. #include <stdio.h>
  2. struct queue
  3. {
  4.   int data[1100];
  5.     int head;
  6.     int tail;
  7. };

  8. struct stack
  9. {
  10.   int data[10];
  11.     int top;
  12. };

  13. int mian()
  14.     {
  15.     struct queue q1,q2;
  16.         struct stack s;
  17.         int book[10];
  18.         int i,t;
  19.         
  20.         //初始队列化
  21.         q1.head=1;q1.tail=1;
  22.         q2.head=1;q2.tail=1;
  23.         //初始化栈
  24.     s.top=0;
  25.         //初始化用来标记的数组,用来标记哪些牌已经在桌上
  26.         
  27.         for(i=1;i<=9;i++)
  28.       book[i]=0;
  29.         
  30.         //依次向队插入6个数
  31.         //小哼在手上的6张牌
  32.         for(i=1;i<=6;i++)
  33.     {
  34.       scanf("%d",&q1.data[q1.tail]);
  35.             q1.tail++;
  36.         }
  37.         //小哈手上的6张牌
  38.         for(i=1;i<=6;i++)
  39.         {
  40.       scanf("%d",&q2.data[q2.tail]);
  41.       q2.tail++;
  42.         }
  43.         while(q1.head<q1.tail && q2.head<q2.tail )
  44.         {
  45.         
  46.       t=q1.data[q1.head];//小哼出一张牌
  47.             //判断小哼当前打出的牌是否能赢牌
  48.             if(book[t]==0)//表明桌上没有牌面为t的牌
  49.             {
  50.             //小哼此轮没有赢
  51.         q1.head++;//小哼已经打出一张牌,所以要把打出的牌出队
  52.                 s.top++;
  53.                 s.data[s.top]=t;//再把打出的牌放到桌上,即入栈
  54.                 book[t]=1;
  55.             }
  56.             else
  57.             {
  58.         q1.head++;
  59.                 q1.data[q1.tail]=t;
  60.                 q1.tail++;
  61.                 while(s.data[s.top]=!t)
  62.                 {
  63.           book[s.data[s.top]]=0;
  64.                     q1.data[q1.tail]=s.data[s.top];
  65.                     q1.tail++;
  66.                     s.top--;
  67.                 }
  68.                 book[s.data[s.top]]=0;
  69.                 q1.data[q1.tail]=s.data[s.top];
  70.                 q1.tail++;
  71.                 s.top--;
  72.             }
  73.             if(q1.head==q1.tail)
  74.             {
  75.         break;
  76.             }
  77.       t=q2.data[q2.head];
  78.       if(book[t]==0)
  79.       {
  80.         q2.head++;
  81.                 s.top++;
  82.                 s.data[s.top]=t;
  83.                 book[t]=1;
  84.             }
  85.             else
  86.             {
  87.         q2.head++;
  88.                 q2.data[q2.tail]=t;
  89.                 q2.tail++;
  90.                 while(s.data[s.top]=!t)
  91.                 {
  92.           book[s.data[s.top]]=0;
  93.                     q2.data[q2.tail]=s.data[s.top];
  94.                     q2.tail++;
  95.                     s.top--;
  96.                 }
  97.                 book[s.data[s.top]]=0;
  98.                 q2.data[q2.tail]=s.data[s.top];
  99.                 q2.tail++;
  100.                 s.top--;
  101.             }
  102.         }
  103.         if(q2.head==q2.tail)
  104.         {
  105.       printf("小哼wim");
  106.             printf("小哼当前手中的牌是");
  107.             for(i=q1.head;i<=q1.tail-1;i++)
  108.         printf(" %d",q1.data[i]);
  109.                
  110.       if(s.top>0)
  111.             {
  112.         printf("桌上的牌是");
  113.                 for(i=1;i<=s.top;i++)
  114.           printf("%d",s.data[i]);
  115.             }
  116.       else
  117.       printf("桌上已经没有牌了");
  118.         }
  119.         else
  120.     {
  121.       printf("小哈wim");
  122.             printf("小哈当前手中的牌是");
  123.             for(i=q2.head;i<=q2.tail-1;i++)
  124.         printf(" %d",q2.data[i]);
  125.                
  126.       if(s.top>0)
  127.             {
  128.         printf("桌上的牌是");
  129.                 for(i=1;i<=s.top;i++)
  130.           printf("%d",s.data[i]);
  131.             }
  132.       else
  133.       printf("桌上已经没有牌了");
  134.         }
  135.                
  136.     getchar();getchar();
  137.   return 0;
  138. }


复制代码

沙发
 楼主| 发表于 2019-3-31 17:40:53 | 只看该作者
谢谢,已经找到问题了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表