解题思路:
注意事项:
参考代码:
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <stdio.h> using namespace std; int solve(int n) { vector<int> str; for (int i = 1; i <= n; i++) str.push_back(i); int index = 0; vector<int>::iterator it = str.begin(); while (str.size() > 1) { index = (index + 2)%str.size(); it = str.begin() + index; it = str.erase(it); index = it - str.begin(); } return str.at(0); } int main(void) { int n = 0; cin >> n; cout << solve(n) << endl; return 0; }
0.0分
0 人评分
C语言训练-求素数问题 (C语言代码)浏览:960 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:664 |
C语言训练-自由落体问题 (C语言代码)浏览:1738 |
【绝对值排序】 (C语言代码)浏览:717 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1292 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:840 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:640 |
【矩阵】 (C++代码)浏览:949 |
C二级辅导-求偶数和 (C语言代码)浏览:673 |
川哥的吩咐 (C语言代码)浏览:611 |