《啊哈算法》打牌问题

#include<stdio.h>

struct queue
{
    int data[1000];
    int head;
    int tail;
 };

 struct stack
 {
    int data[10];
    int top;
};

int main()
{
    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;
    }
    for(i = 1;i <= 6; i++)
    {
        scanf("%d", &q1.data[q1.tail]);
        q1.tail++;
    }
    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)
        {
            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("小恒win\n");
        printf("小恒当前的手牌是");
        for(i = q1.head; i<= q1.tail-1;i++)
            printf(" %d", q1.data[i]); 
        if(s.top > 0)
        {
            printf("\n桌上的牌是");
            for(i = 1;i<=s.top;i++)
               printf(" %d", s.data[i]);   
        }
        else
           printf("\n桌子上已经没牌");
    }
    else
    {
        printf("小哈win\n");
        printf("小哈现在的手牌为");
           for(i = q2.head;i<q2.tail-1;i++)
              printf(" %d", q2.data[i]);
        if(s.top>0)
        {
            printf("\n桌子上的牌是");
            for(i = 1;i <= s.top; i++)
               printf(" %d", s.data[i]);
        }
        else
            printf("\n桌上已经没有牌了");
    }
    getchar(); getchar();
    return 0;
}

这段代码我在编译器上面运行了一遍,但不知道为什么就是输出不了结果。。。。
求大神解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值