http://en.wikipedia.org/wiki/Josephus_problem用户可以选择圈子里有多少人。用户可以选择每个人的值。用户可以选择人员死亡的计数数量。例如。用户选择5,每5个人将死亡。
我在想像这样的东西-用户选择数量的人前50 PeopleArray变成PeopleArray50
用户在PeopleArray50中选择元素的值他们必须为这50个元素键入50个值
Death User选择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
}
} 发布于 2014-10-23 06:42:07
如果我没理解错的话,你想做的事情应该是这样的…
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);
}或者假设totalPeoplenthPerson = 0;这将从总人员列表中删除第n个人。
https://stackoverflow.com/questions/26516971
复制相似问题