Magician Licensing Issues

Source: Internet
Author: User

Problem Description:

The magician used a deck of 13 black label, pre-lined them up and stacked together, face down. Said to the audience: "I do not look at cards, only a few can guess what each card is, I loudly count, you listen, do not believe?" Live demonstrations. "The magician put the top card number at 1, turn him over. It is a spade a, put the spades a on the table, the second number 1, 2, the first card placed under these cards, the second card turned over, just the Spades 2, also put it on the table in turn will be 13 cards all turned out, accurate.

Solution:

Using the circular link list to implement

Code Description:

#include <stdio.h> #include <stdlib.h> #define N 13//Magician's number of cards (a-k in turn with 1~13) typedef struct NODE{INT data; struct Node *next; }NODE;TYPEDEF struct node *linklist;//constructs a circular list node* CreatList1 (struct node *la,int n) {//constructs a circular linked list (the value of the node is 0) returns the first address of the loop list int i ; struct Node *p,*s; La = (linklist) malloc (sizeof (Node)); La->next = Null;p = la;for (i = 1;i <= n;i++) {s = (linklist) malloc (sizeof (Node)); s->data = 0;s->next = P->ne Xt;p->next = S;p = P->next;} P->next = La->next;return p;} Analog magician cards to list assignment node* magician (struct Node *la,int n)//l->la n->n{int i,j,count = 2;//count used to count Node *p,*q;p = la-&  Gt;next;//p->data = = 1p->data = 1;for (i = 2;i <= n;i++) {for (j = 1;j <= count;j++) {p = p->next;if (p->data ! = 0) {j--;}} P->data = i;count++;} return la->next;} int main (int argc,char* argv[]) {int i; Node *l,*p,*q; L = CreatList1 (l,n); L = Magician (l,n);//l->la n->np = l;printf ("Pre-order emission sequence: \ n"); for (i = 1;i <= n;i++) {printf ("%3d", p->data);p = P->next;} printf ("\ n"); System ("pause"); return 1;}

  

Magician Licensing Issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.