⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 约瑟夫环问题.txt

📁 这是一个约瑟夫环的问题
💻 TXT
字号:
#include<stdio.h>
#include<conio.h>
void main()
{
struct s1{
int password;
int num;
struct s1 *next;
}*p,*q,*top=0;
int m,n,i,j;
printf("input how many people:");
scanf("%d",&n);
printf("input the number m:");
scanf("%d",&m);
for(i=0;i<n;i++){
p=(struct s1*)malloc(sizeof(struct s1));
if(p==NULL){
printf("Memory allocate failure!");}
if(top==0){top=p;q=p;}
scanf("%d",&p->password);
p->num=i+1;
q->next=p;
q=p;
}
q->next=top;
p=top;
q=p; 
for(j=0;j<n;j++){
for(i=0;i<m-1;i++){
q=p;
p=q->next;
}
printf("\n%d",p->num);
m=p->password;
q->next=p->next;
free(p);
p=q->next;
}
getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -