- 新增现代 C++ 教程的 Preface 章节,包括英文和中文版本 - 添加 C++ Primer 练习代码 - 新增 Learn C++ 教程的 C++ 开发简介章节 - 添加头文件解析文档 - 更新 mkdocs.yml,包含新教程的目录结构 - 修改项目设置,使用 Python 3.10环境
31 lines
675 B
C++
31 lines
675 B
C++
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
using std::vector;
|
|
|
|
int main() {
|
|
vector<int> v;
|
|
int w;
|
|
cout << "请输入数字" << endl;
|
|
while (cin >> w) {
|
|
v.push_back(w);
|
|
}
|
|
if (v.cbegin() == v.cend()) {
|
|
cout << "没有任何元素" <<endl;
|
|
return -1;
|
|
}
|
|
cout << "首尾两项的和为:" <<endl;
|
|
auto begin = v.begin();
|
|
auto end = v.end();
|
|
for(auto it = begin; it != begin + (end - begin) / 2; it ++){
|
|
cout << (*it + *(begin + (end - it) - 1))<< " ";
|
|
|
|
if (v.size() % 2 != 0)
|
|
cout << *(begin + (end - it + 1)/ 2);
|
|
cout <<endl;
|
|
}
|
|
|
|
return 0;
|
|
} |