?? 約瑟夫環問題.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 + -