1, there are n people around in a circle, sequential numbering, from the first person began to count, where 3 of the people out of the circle, write procedures, ask the last left is the original number of the person.
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int date;
struct Node *next;
}node,*linklist;
linklist createlist (int n) {
int i;
Linklist head,pre,p;
Head=pre= (linklist) malloc (sizeof (Node));
head->date=1;
for (i=2;i<=n;i++) {
p= (linklist) malloc (sizeof (Node));
p->date=i;
pre->next=p;
Pre=p;
}
pre->next=head;
return head;
}
void Out_circle (linklist head) {
int n;
Linklist pre,p;
P=head; N=1;
while (p->next!=p) {
Pre=p; p=p->next;
n++;
if (n==3) {
pre->next=p->next;
Free (p);
p=pre->next;
N=1;
}
}
printf ("Last left is%d bit: \ n", p->date);
}
int main () {
int n;
Linklist head;
printf ("Input number: \ n");
scanf ("%d", &n);
Head=createlist (n);
Out_circle (head);
return 0;
}