解题思路:
注意事项:在判断最后一个函数中的迭代器要两次判断尾
参考代码:
#include <iostream> #include <vector> using namespace std; void updatePeople(vector<int> &data, int &n) { for (int i = 0; i < n; i++) { data.push_back(i + 1); } } int lastPeopleNumber(vector<int> &data, int &m) { size_t temp = 0; int indx = 1; try { while (data.size() > 1) { temp++; indx++; if (data.begin() + temp == data.end()) { temp = 0; } if (indx == m) { data.erase(data.begin() + temp); indx = 1; } if (data.begin() + temp == data.end()) { temp = 0; } } } catch (const char *message) { cerr << "error:" << message << endl; } return data.at(0); } int main() { int n, m; vector<vector<int>> multi_group(0, vector<int>(2)); vector<int> people; while (cin >> n >> m) { multi_group.push_back(vector<int>{n, m}); } for (auto temp : multi_group) { people.clear(); n = temp.at(0); m = temp.at(1); updatePeople(people, n); cout << lastPeopleNumber(people, m) << endl; } return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.5 (Java代码)浏览:1252 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:668 |
C语言训练-求具有abcd=(ab+cd)2性质的四位数 (C语言代码)浏览:622 |
程序员的表白 (C语言代码)浏览:707 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:597 |
DNA (C语言代码)浏览:564 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:537 |
Tom数 (C语言代码)浏览:517 |
1134题解(求分析)浏览:795 |
小O的乘积 (C语言代码)浏览:1062 |