📄 yuesefu.c
字号:
#include<stdio.h>
#include <windows.h>
#include<malloc.h>
#define LEN sizeof(struct hao)
int m,n;
struct hao
{
int num;
int scr;
struct hao *next;
};
void main()
{
int i;
struct hao *head;
struct hao *p1,*p2;
printf(" 约瑟夫环\n\n");
printf("请输入链表长度:");
scanf("%d",&n);
p1=p2=head=(struct hao*)malloc(LEN);
p2->num=1;
printf("请输入第1个密码:");
scanf("%d",&p2->scr);
for(i=0;i<n-1;i++)
{p1=(struct hao*)malloc(LEN);
p1->num=i+2;
printf("请输入第%d个密码:",p1->num);
scanf("%d",&p1->scr);
p2->next=p1;
p2=p1;
}
p1->next=head;
printf("请输入第一个m值");
scanf("%d",&m);
printf("输出排序:");
p1=head;
do{
for(i=1;i<m;i++)
{
p2=p1;
p1=p2->next;
}
printf("%d",p1->num);
m=p1->scr;
p1=p1->next;
p2->next=p1;
}while(p2!=p2->next);
printf("%d\n\n",p2->num);
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -