解题思路:
注意事项:
参考代码:
#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 人评分
点我有惊喜!你懂得!浏览:1097 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1541 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:554 |
十->二进制转换 (C语言代码)浏览:1304 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:665 |
三角形 (C语言代码)浏览:928 |
大家好,我是验题君浏览:579 |
字符串输入输出函数 (C语言代码)浏览:2498 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:531 |
C二级辅导-温度转换 (C语言代码)浏览:737 |