作者在 2010-12-08 22:42:08 发布以下内容
#include <stdio.h>
#include <malloc.h>
#define null 0
typedef struct joseph
{int count;
int mima;
joseph *next;
}ath;
int n,m,i,j;
ath *head,*p,*q;
void main()
{void creat();
void shuru();
void mima1();
head=(ath*)malloc(sizeof(ath));
head->next=null;
p=head;
printf("请输入几个人围坐一圈:\n");
scanf("%d",&n);
for(i=1;i<n;i++)
creat();
shuru();
mima1();
}
void creat()
{q=(ath*)malloc(sizeof(ath));
q->next=head;
p->next=q;
p=p->next;}
void shuru()
{p=head;
for(i=1;i<=n;i++)
{p->count=i;
printf("请输入第%d个人的密码:\n",i);
scanf("%d",&p->mima);
p=p->next;}
for(p=head;p!=q;p=p->next)
printf("第%d个人的密码是:%d\n",p->count,p->mima);
printf("第%d个人的密码是:%d\n",p->count,p->mima);
}
void mima1()
{int l;
p=head;
l=6;
while(p->next!=p)
{for(i=1;i<l;i++)
{q=p;p=p->next;}
q->next=p->next;
printf("%d ",p->count);
l=p->mima;
p=p->next;
}
printf("%d ",p->count);}
#include <malloc.h>
#define null 0
typedef struct joseph
{int count;
int mima;
joseph *next;
}ath;
int n,m,i,j;
ath *head,*p,*q;
void main()
{void creat();
void shuru();
void mima1();
head=(ath*)malloc(sizeof(ath));
head->next=null;
p=head;
printf("请输入几个人围坐一圈:\n");
scanf("%d",&n);
for(i=1;i<n;i++)
creat();
shuru();
mima1();
}
void creat()
{q=(ath*)malloc(sizeof(ath));
q->next=head;
p->next=q;
p=p->next;}
void shuru()
{p=head;
for(i=1;i<=n;i++)
{p->count=i;
printf("请输入第%d个人的密码:\n",i);
scanf("%d",&p->mima);
p=p->next;}
for(p=head;p!=q;p=p->next)
printf("第%d个人的密码是:%d\n",p->count,p->mima);
printf("第%d个人的密码是:%d\n",p->count,p->mima);
}
void mima1()
{int l;
p=head;
l=6;
while(p->next!=p)
{for(i=1;i<l;i++)
{q=p;p=p->next;}
q->next=p->next;
printf("%d ",p->count);
l=p->mima;
p=p->next;
}
printf("%d ",p->count);}