002 -- 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: \n");
    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", &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", &n);

    q=p=head;

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            printf("%d",p->data);
            p = p->next;
        }
        printf("\n");
        q = q->next;
        p = q;
    }
}

int main()
{
    linklist p;

    p=CreateLinkList();
    PrintLatin(p);

    return o;
}
时间: 2024-07-28 16:37:19

002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin的相关文章

002 -- Circle LinkList 2 -- connect 2 circle link lists

The operation fullfilled codes: // A, B is the rear for 2 LinkList with nodes LinkList Connect(LinkList A,LinkList B) { p = A->next; // use p to store A list head A->next = B->next->next; // A change to point to b1 as the next. free(B->next

001 -- Circle LinkList, list initiate, add a new node, delete a node, and List traverse

#include <studio.h> #include <stdlib.h> typedef struct CLinkList { int data; struct CLinkList *next ; } node; /*initiate a circle list*/ void ds_init(node **pNode) { int item; node *temp; node *target; printf("please input the value of th

002 -- Circle LinkList_Josephus Story

Circle List puzzle Josephus Story: there is 41 people , 39 of them have the agreement that: all these 41 people stand as a circle, and one of them count from 1, and the one count to 3, suicide ! and the people next to him count from 1 again, untill a

数据结构关于单链表的一些操作的源代码

单链表的可以有许多问题,这是我特意整理一下的有关他的相关操作,给出代码,有需要的可以自己调试,重要的就是关于环的一些操作: #include <iostream>#include <cstdio>#include <cstdlib>#include <ctime>using namespace std;typedef int Elemtype;typedef struct Node{ Elemtype data; struct Node *next;}Nod

Mathametica_00_The Hertz&#39; dipoles

Mathematica_00_画出赫兹偶极子的电场.磁场.坡印廷矢量的图像随时间的变化 Manipulate[ Pane[Module[{gg, inset1, inset2}, inset1 = Inset[Graphics[ Text[Style["\!\(\*SubscriptBox[\(p\), \(0\)]\)", 20, White]]], {0, 2.5}]; inset2 = Inset[Graphics[ Text[Style[ Row[{Subscript[Styl

leetcode python 002

##002 Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8# 链表节点都是一位数字,以上可以视为243+564=807#先定义节点和链表类import numpy as npimport time class Node(object):    def __init__(self,n,next_node=None):        self.data=n        self.next=next_node

作业:JavaScript(数组篇-poker)给我的徒弟出个题。。。记得早点写完,然后大家3人可以早点打牌了

吐槽一下:“今天实际上我左思右想,写个什么东西好呢!手上的笔转了半天....最后还是给自己留点余地!看着他们什么酒店管理系统,呼叫中心系统之类的....简直是把自己固定死了!感觉一撸到底的感觉!!!我们是程序员所以我觉得要思想灵活点HOHO...” 今天只是想写一篇关于JavaScript数组的一篇文章 以前我认为我已经完全把数组掌握了!但是去年面试的时候被问呆了!!瞬间感觉自己萌萌哒!!所以把书看完了不算会!所以这次为了让我的徒弟能够不再犯我当年的错误...哼哼!我决定让她来一次实战!!!不能

657. Judge Route Circle 判断线路成圆

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte

html入门之002

html实体 &nbsp 空格 &lt < &gt > &quot 引用 &copy 版权 &times X &divide ÷ &yen ¥ 列表标签 ul 属性type(disc(默认/square/circle) li 列表项 属性type值同上 ol 有序列表 属性 reversed(降序) type(1/a/A/I) start(值数字) dl 定义列表 dt 列表项目的标题 列表项目的描述 文本标签 *em 强调 表现