?? 123.c
字號(hào):
#include <stdio.h>
#include "stdlib.h"
struct Node
{
int num;
int data;
struct Node *link;
};
void main()
{
struct Node *h, *u, *p,*o;
int n, m, i,r=0;
char q;
printf("Please input how many people join this game:\n");
scanf("%d",&n);
getchar();
printf("Now,which one you want to be the first man to leave:\n");
scanf("%d",&m);
h = u = (struct Node*)malloc(sizeof(struct Node));
h->num = 1; /*標(biāo)記頭結(jié)點(diǎn)*/
for(i = 2; i <= n; i++) /*創(chuàng)建連表*/
{
u->link = (struct Node*)malloc(sizeof(struct Node));
u = u->link;
u->num = i;
}
u->link = h; /*構(gòu)成循環(huán)*/
printf("Ok,let's give everyone a key:\n");
o=h;
for(i=1;i<=n;i++)
{
printf("The key of the people%d:",i);/*向每一個(gè)人賦密碼值*/
scanf("%d",&o->data);
o=o->link;
}
system("clr");
do{
printf("\nOK,do you want to know the sequence of the leave people?('Y'\'N'):");
scanf("%c",&q);
if(q=='Y'||q=='y') r=1;else r=0;
}
while(!r);
while (n)
{
for(i = 1; i < m; i++)
u = u->link; /*找到出對(duì)的人的前一個(gè)*/
p = u->link; /*p指向要出對(duì)的人*/
u->link = p->link; /*u指向出隊(duì)的下一個(gè)*/
printf("%4d", p->num);
m=p->data;
free(p);
n--;
}
printf("\n\n");
getch();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -