?? 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 + -