我现在正在处理的问题是 here ,但我当然不是在寻找这个作业问题的完整答案。我所要求的只是问题最后部分的步骤。这是我目前所拥有的:
int main()
{
cout << "Please enter the number of guests attending your party: ";
int k;
cin >> k;
cout << "Please enter the number of rounds of removal you'd like to perform: ";
int m;
cin >> m;
for (int i = 1; i <= m; i++) {
cout << "Please enter the multiple at which you'd like the removal to be at for round " << i << ": ";
int r;
cin >> r;
if (k % r == 0) {
k - r;
}
cout << k << endl;
}
system("pause");
}
这一切让我很困惑,我真的不知道该去哪里寻找答案。似乎我需要一个数组来解决这个问题,但 C++ 中的数组不能是可变的,并且数组长度将是 k,一个可变输入。任何帮助将不胜感激。
最佳答案
我读过那个问题。你需要一个像链表这样的动态列表,因为你需要从不同的索引中放置和删除不同的项目,所以使用数组会很困难。
尝试使用 std::vector 或 std::list,你可以添加或删除任何列表
#include <list>
std::list<int> mylist;
如何从列表中添加和删除值,查看此链接 http://en.cppreference.com/w/cpp/container/list
要使用您自己的链接列表,请查看此链接 How could i create a list in c++?
关于c++ - 聚会请柬,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34915539/