十三个小孩围成圈做游戏 从第3个人开始循环报数,报数为5者出圈,接着重…

十三个小孩围成圈做游戏.从第3个人开始循环报数,报数为5者出圈,接着重新报数, 求出圈顺序.(C语言)
匿名用户    2012-03-23 08:24    

满意回答

请参考下:http://www.92linux.tk/read.php?tid=60

匿名用户   2012-03-23 09:32
宝宝知道提示您:回答为网友贡献,仅供参考。

为您推荐:

其他回答

#include #include typedef struct node { int data; struct node *next; } Lnode; Lnode * create (int n) {int i; Lnode *h,*p,*r=(Lnode*)malloc(sizeof(Ln...ode)); r->data=n; h=r; for (i=n-1;i>0;i--) {p=(Lnode*)malloc(sizeof(Lnode)); p->data=i; p->next=h; h=p; } r->next=h; return h; } void jeseph(Lnode *p,int m) { Lnode *q; int j=0; printf("outqueue order:\n"); while (p->next !=p) { j++; if(j==m-1) { q=p->next; p->next=q->next;//删除q结点 printf("%d ",q->data);//将q结点的数据输出 j=0;free(q); } p=p->next;//指针后移 } printf("%d\n",p->data); free(p); } int main () { Lnode *h; int m,n; printf("Please input n,m="); //n=13 m=5 scanf("%d,%d",&n,&m); h=create(n); jeseph(h,m); return 0; } 运行: Please input n,m=13,5 outqueue order: 5 10 2 8 1 9 4 13 12 3 7 11 6

全部展开 收起
匿名用户    2012-03-23 09:01

约瑟夫环问题,可上网百度一下,有很多

匿名用户    2012-03-23 08:57