- 原题题目
- 代码实现
- 提交结果
原题题目
代码实现
#include#include using namespace std; int main() { vector a; int n, m, x = 0; cout << "Input n and m:"; cin >> n >> m; a.resize(n); for (int i = 0; i < n; i++) { a[i] = i + 1; } int pos = 0; while (a.size() > 1) { for (int i = 0; i < m - 1; ++i) pos = (pos + 1) % a.size(); a.erase(a.begin() + pos); } cout << "Result:" << a[0] << endl; return 0; }
提交结果



