食物链

#include
#include
struct node
{
    int TYPE;
    long x;
    long y;
    struct node *next;
};
/*************************************/
  struct node * inputfun(long k)/*K表示说话的句数*/
  {
      int i;
      struct node *p,*s,*head;
      p=(struct node *)malloc(sizeof(struct node));
      scanf("%d%d%d",&(p->TYPE),&(p->x),&(p->y));
      head=p;
      s=p;
      for(i=0;i      {
          p=(struct node *)malloc(sizeof(struct node));
        s->next=p;
          scanf("%d%d%d",&(p->TYPE),&(p->x),&(p->y));
        s=p;    
      }
      p->next=NULL;
      return head;
  }
/*************************************/
int checkfun(struct node *head,long n)/*head是返回链表的头指针,n是表示动物的总数量*/
{
    long error=0,temp=0,loop=0,i;
    struct node *p,*q,*t;
        p=head;
    for(;;)
    {
        if((p->TYPE==2&&p->x==p->y)
            ||((p->x>n)||(p->y>n)))
            error++;
            if(p->next==NULL)
                break;
                p=p->next;
        }
        p=head;
        t=head;
        q=(struct node *)malloc(sizeof(struct node));
    for(;;)
    {
        q->x=t->x;
        q->y=t->y;
        q->TYPE=t->TYPE;
        for(;;)
        {
            if(((p->x==q->x)&&(p->y==q->y))&&
                (p->TYPE!=q->TYPE))
            temp++;
            if(temp>1) 
                {
                    temp=0;
                error++;
            }
            if((p->TYPE==q->TYPE)&&(p->x==q->y)&&
                (p->y==q->x))
                loop++;
                if(loop>1)
                    {
                        loop=0;
                    error++;
                }
                    if(p->next==NULL)
                        {
                            p=head;
                            break;
                        }
                    p=p->next;
            
        }    
        if(t->next==NULL)
            break;
            t=t->next;
        }    
        return error;    
    }
    /***************************************************/
    int main(void)
    {
        long error,animal,j;
        struct node *pt;
        printf("输入动物的总数量/n");
        scanf("%d",&animal);
        printf("输入说法的总数量/n");
        scanf("%d",&j);
        printf(" 用规定的表示方法输入你的说法/n");
        pt=inputfun(j);
        error=checkfun(pt,animal);
        printf("假话的数目是%d/n",error);
        return 0;
    }
    

你可能感兴趣的:(食物链)