Josephus使用数组进行问题
Josephus prob using arrays?
http://en.wikipedia.org/wiki/Josephus_problem用户可以选择圈子里有多少人。用户可以选择每个人的价值。用户可以选择死亡人数。例如,用户选择5人,每5人死亡。
我在想这样的事情——用户选择50以外的人数PeopleArray成为PeopleArray[50]
用户选择PeopleArray中元素的值[50]他们必须为的50个元素键入50个值
死亡用户选择3,所以每三个人死亡一次,我该如何从数组中删除这个数字。
问题^-不确定如何使用阵列进行上述操作
int main(){
int people = 5;
int peopleArray[5];
int peopleValue = 1;
int death;
cout << "Enter the amount of people: ";
cin >> people;
peopleArray[people];
for(int x = 1;x<=people;x++){
cout << "Enter the value of person #" << x << ":";
cin>> peopleValue;
peopleArray[peopleValue]; //Suppose to put the value into the array
}
}
如果我正确理解你,你想做的事情会是。。。
vector<int> totalPeople;
int totalIn;
int deathIn;
int person = 1;
int nthPerson = 0;
cout << "Enter total number of people." << endl;
cin >> totalIn;
cout << endl << "Pick the nth person." << endl;
cin >> deathIn;
for ( int i = 0; i < totalIn; i++ )
{
totalPeople.pushback(person++);
}
nthPerson = deathIn - 1;
while ( nthPerson < totalPeople.size() )
{
totalPeople.erase(totalPeople.begin() + nthPerson);
nthPerson = nthPerson + (deathIn -1);
}
或者说totalPeople[nhPerson]=0;这将从人员的总列表中删除第n个人员。
相关文章:
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 输入std::数组时出现问题
- 类对象数组的问题会导致崩溃
- 传递二维数组时出现问题
- 从 C++ 中的函数返回数组地址问题
- 使用数组时出现问题
- 打印问题.我在数组中打印值时遇到一些问题
- C++:__aligned(__alignof__) 导致字符数组数据出现问题?
- 将字节数组转换为带有字节序问题的指针
- C++ 填充数组时遇到问题
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 当我尝试通过 arduino 上的引用传递布尔数组时出现问题
- 我正在尝试解决一个需要数组总和值但代码不起作用的问题,我想做这样的事情
- 编写 cin.get() 以接收字符数组时出现问题
- 在 C++ Consol 中的数组中执行用户命令时出现问题
- 存储另一个函数返回的布尔数组时遇到问题
- 当我在 CLion 中读取数组中的 txt 文件时C++编码问题
- 运行时C++数组初始化问题
- 我在解决此错误时遇到问题.我正在努力在主函数中传递数组