解题思路:
注意事项:
参考代码:
#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语言代码)浏览:852 |
C语言考试练习题_保留字母 (C语言代码)浏览:575 |
printf基础练习2 (C语言代码)浏览:593 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:628 |
C语言程序设计教程(第三版)课后习题8.4 (Java代码)浏览:733 |
钟神赛车 (C++代码)浏览:866 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1447 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1042 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:544 |
WU-蓝桥杯算法提高VIP-勾股数 (C++代码)浏览:1607 |