Joseph队列解法
2015-06-02 22:48
211 查看
int main(){ while(true){ int a = 0, b = 0; int numOfPeople = 0, numToSpare = 0; cout<<"input number of people:"; cin>>numOfPeople; cout<<"input number to spare per circle:"; cin>>numToSpare; determinSurvivor(numOfPeople, numToSpare, a, b); cout<<"the last two person to be topilled is "<<a<<" and "<<b<<endl; if(stopCircle()) break; } return 0; } bool stopCircle(void){ string flag; while(true){ cout<<"Do you want to try another file? "; flag = getLine(); if( flag == "yes" ) return false; else if( flag == "no" ) return true; cout<< "Please answer 'yes' or 'no' "<<endl; } } void determinSurvivor(int numOfPeople, int numToSpare, int& last, int& nextToLast){ Queue<int> circle; for(int i = 1; i <= numOfPeople; i++) circle.enqueue(i); while(!circle.isEmpty()){ for(int j = 0; j < numToSpare; j++){ int next = circle.dequeue(); circle.enqueue(next); } nextToLast = last; last = circle.dequeue(); cout<<"the "<<last<<" person should be topilled"<<endl; } }
相关文章推荐
- 图像配准基础理解
- Linux 安装Redis全过程日志
- Linux 安装Redis全过程日志
- Linux 安装Redis全过程日志
- 浏览器兼容性测试的分类
- uva 10791 Minimum Sum LCM
- Android学习之——SpannableString和TextView的使用及研究
- OWIN
- double freeバグのデバッグ.
- 易宝网上支付平台的PHP接口代码
- 2015年6月做题记录
- (转)FFMPEG解码H264拼帧简解
- DB天气app冲刺二阶段第六天
- iOS开发的一些奇巧淫技
- HTML5大数据可视化效果(一)彩虹爆炸图
- super
- HDFS写文件解析
- HDFS写文件解析 分类: hadoop 2015-06-02 22:46 146人阅读 评论(0) 收藏
- 团队冲刺阶段二第七次站立会议
- 黑马程序员-OC之面向对象的三大特性:封装、继承和多态