There are many online sayings. Here is a brief description.
A group of people in a circle, everyone has their own key. After the dequeue with its key to do the next loop out of the team number.
Source
#include <stdio.h> #include <stdlib.h>typedef struct _node{int ord;//order int key;//keystruct _node* next;} Node,*pnode;pnode Create () {int K,o=1;pnode head,cur,h;if (scanf ("%d", &k), k) {head=h=cur= (pnode) malloc (sizeof ( Node)); h->ord=o++;h->key=k;h->next=null;} Else{return NULL;} while (scanf ("%d", &k), k) {cur= (pnode) malloc (sizeof (Node)); cur->ord=o++;cur->key=k;cur->next=null;h- >next=cur;h=cur;} H->next=head;return Head;} void Joh (Pnode head,int start,int m) {pnode h=head,tem;int count=1;while (h->next->ord!=start) {h=h->next;} while (H->next) {while (count<m) {h=h->next;++count;} if (count==m) {m=h->next->key; printf ("ord=%d,key=%d\n",h->next->ord,h->next-> Key); For testing with Tem=h->next;h->next=h->next->next;free (TEM); count=1;} if (h==h->next) {printf ("ord=%d,key=%d\n", H->next->ord,h->next->key); free (h); break;}}} void Show (Pnode head) {pnode h=head;while (h) {printf ("ord=%d,key=%d\n", H->ord,h->key); H=h->next;if (H==head) {break;}}} int main () {Pnode head=create (); Show (head);p rintf ("\ n"); Joh (head,3,3); return 0;}
Test data
ord=1,key=2
Ord=2,key=3
Ord=3,key=4
ord=4,key=2
Ord=5,key=5
Ord=6,key=3
ord=7,key=2
Ord=8,key=4
Ord=9,key=3
Ord=10,key=4
ord=11,key=2
Ord=12,key=3
ord=13,key=2
Ord=5,key=5
Ord=10,key=4
ord=1,key=2
Ord=3,key=4
Ord=8,key=4
ord=13,key=2
ord=4,key=2
ord=7,key=2
ord=11,key=2
Ord=2,key=3
Ord=12,key=3
Ord=6,key=3
Ord=9,key=3
Joseph Ring Question