华为机试——约瑟夫环变种
来源:互联网 发布:淘宝叶罗丽娃娃24元 编辑:程序博客网 时间:2024/06/06 18:37
华为机试——约瑟夫环变种
输入一个由随机数组组成的数列(数列中每个数均是大于0的整数,长度已知),和初始计数值m。从数组首位置开始计算,计算到m后,将该数列该位置数值替换计数值m,并将数列该位置数值出列,然后从下位置从新开始技术,知道数列所有数值出列位置。如果计数到达数列尾段,则返回数列首位置继续计数。请编写程序实现上述技术过程,同时输出数值出列的顺序。
示例:
输入:int input_array[]={3,1,2,4},int len=4,m=7;
输出:output_array[]={2,3,1,4}
#include<iostream>#include<list>#include<algorithm>using namespace std;void Joes(int n,list<int> &number,int m){ if(n < 1||m <1 ) return ; list<int>::iterator current=number.begin(); while(number.size()>0) { while(--m) { current++; if(current == number.end()) current=number.begin(); } m=*current; cout<<*current<<" "; list<int>::iterator next=++current; if(next == number.end()) next=number.begin(); --current; number.erase(current); current=next; }}int main(){ int len,m; list<int> number; cin>>len; int num; for(int i=0;i<len;i++) { cin>>num; number.push_back(num); } cin>>m; Joes(len,number,m); return 0;}
0 0
- 华为机试——约瑟夫环变种
- 华为机试—约瑟夫环
- 华为机试—约瑟夫环
- 华为机试——约瑟夫环问题(总结)
- 华为机试.约瑟夫环
- 华为机试约瑟夫环
- 约瑟夫环—华为试题
- 约瑟夫环变种
- 华为机试---约瑟夫环问题
- 华为机试—约瑟夫环替换计数器m(数组解决)
- 华为机试—约瑟夫环替换计数器m(循环链表解决)
- 华为机试 - 约瑟夫问题
- 华为招聘机试整理15:约瑟夫环
- 华为招聘机试整理16:约瑟夫环应用
- 华为机试一道关于约瑟夫环的问题
- 华为机试:约瑟夫环换m值
- 约瑟夫环及其变种算法 java实现
- 2013华为校园招聘上机题——约瑟夫环
- Myelicpse整合Activiti插件
- svm入门之四线性分类器求解与问题描述
- 数组的初始化与memset的注意事项
- 10天学通MongoDB---资料链接-----阿冬专栏
- Bit-reversal permutation
- 华为机试——约瑟夫环变种
- matlab中./与/有什么区别
- VLAN帧格式
- CentOS6.5安装
- 【转】减少.NET应用程序内存占用的一则实践
- 黑马程序员--正则表达式
- python 格式规范工具 autopep8 Tool to convert Python code to be PEP8 compliant
- svm入门之五、六线性分类器问题描述与求解
- SQLite3 C语言API入门