• 004 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin


    000--Magic Poker

    Put the poker with specific sequence, so that they can show as below:

    count 1, open the first card as A, count 2, the first one place to bottom and open the second one as 2; for 3, the first 2 cards put to the bottom, and open the third one 3 ......

    #include <stdio.h>
    #include <stdlib.h>
    
    #define CardNumber 13 
    
    typedef struct node
    {
        int data;
        struct node *next;
    }sqlist, *linklist;
    
    linklist CreateLinkList()
    {
        linklist head = NULL; //the head node with NULL
        linklist s, r;
        int i;
        
        r = head;
        
        for(i=1;i<=CardNumber;i++)
        {
            s = (linklist)malloc(sizeof(sqlist));
            s->data = 0;
            
            if(head==NULL)
                head = s; // for the first newly create node, it becomes head now. the next time, head = o. 
            else
                r->next = s;
            
            r = s;
        }
        
        r->next = head; //the last node points to the first node=head 
        
        return head;
    }
    
    //count the sequence for distributing the card
    void Magician(linklist head)
    {
        linklist p;
        int j;
        int Counter = 2;
        
        p=head;
        p->data = 1; //the first card as 1
        
        while(1)
        {
            for(j=0;j<Counter;j++)
            {
                p=p->next;
                if(p->data!=0)
                {
                    p->next;
                    j--;
                }
            }
            if(p->data == 0)
            {
                p->data = Counter; 
                Counter++;
                
                if(Counter==14)
                    break;
            }
        }
    }
    
    void DestroyList(linklist* list)
    {
        free(list);
    }
    
    int main()
    {
        linklist p;
        int i;
        
        p = CreateLinkList();
        Magician(p);
        
        printf("please set the card with the sequece as below: 
    ");
        for(i=0;i<CardNumber;i++)
        {
            printf("card%d", p->data);
            p=p->next;
        }
        
        DestroyList(&p);
        
        return 0;
    }

     

    001-- Latin print 

    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct node
    {
        int data;
        struct node *next;
    }sqlist, *linklist;
    
    linklist CreateLinkList()
    {
        linklist head = NULL;
        linklist s,r;
        int i,n ;
        
        printf("please input the latin Number you want to create: ");
        scanf("%d
    ", &n);
        r = head;
        
        for(i=1;i<=n;i++)
        {
            s = (linklist)malloc(sizeof(sqlist));
            s->data = i;
            
            if(head==NULL)
                head=s;
            else
                r->next = s;
            
            r=s;
        }
        
        r->next = head;
        return head;
    }
    
    void PrintLatin(linklist head)
    {
        linklist p,q;
        int i,j,n;
        printf("please input the latin Number you want to create: ");
        scanf("%d
    ", &n);
        
        q=p=head;
        
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                printf("%d",p->data);
                p = p->next;
            }
            printf("
    ");
            q = q->next;
            p = q;
        }
    }
    
    int main()
    {
        linklist p;
        
        p=CreateLinkList();
        PrintLatin(p);
        
        return o;
    }

  • 相关阅读:
    Gram 矩阵性质及应用
    Gram 矩阵性质及应用
    经典公开课、好的学习网站
    经典公开课、好的学习网站
    机器学习、深度学习经典课程
    机器学习、深度学习经典课程
    机器学习竞赛(代码)
    机器学习竞赛(代码)
    数学类网站、代码(Matlab & Python & R)
    数学类网站、代码(Matlab & Python & R)
  • 原文地址:https://www.cnblogs.com/Shareishappy/p/7529891.html
Copyright © 2020-2023  润新知