#include <stdio.h>
struct child {
int num;
child * next;
};
int main()
{
child *head; //头指针
int n,key;
child *child_; //当前指针
child *child_out; //child_out 出局孩子的指针
child s,t;
s.next=NULL;
s.num=0;
printf("请输入 孩子 数量 : ");
scanf("%d",&n);
printf("\n请输入 游戏密码 :");
scanf("%d",&key);
head=&s;
child_=head;
child_out=head;
//创建孩子链表
for (int i=0;i<n;i++) {
t.num=i+1;
t.next=NULL;
child_->next=&t;
child_=child_->next;
}
child_->next=head;
child_=head;
int cout;
int num_child=n;
while (num_child!=1) {
cout=1;
while (cout!=key){
cout++;
child_out=child_out->next;
}
printf("\n第 %d 个出局的孩子是 %d",n-num_child+1,child_out->next->num);
child_=child_out->next;
child_out->next=child_->next;
child_->next=NULL;
num_child--;
}
return 0;
}
约瑟夫环问题,儿童数数游戏
4星 · 超过85%的资源 需积分: 9 24 浏览量
2012-07-07
12:59:30
上传
评论
收藏 165KB RAR 举报
zhangkan3837
- 粉丝: 1
- 资源: 6
最新资源
- 基于 Java的扫雷程序毕业设计
- axure9 里面有码 axure9 里面有码
- 551-2404242311-1.amr
- 自己搭建的关于springboot整合mybatis的框架.zip
- 这是一个保存Springboot+MyBaits项目的仓库.zip
- tensorflow-gpu-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.4-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-gpu-2.7.4-cp38-cp38-manylinux2010-x86-64.whl
- 詹佳 陈敏 口语2.mp3
- 图书管理系统毕业设计Java语言实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈