64,648
社区成员
发帖
与我相关
我的任务
分享
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
const int N = 100;
int main()
{
std::vector<int> shu;
std::vector<int> he2;
for (int i = 1; i <= N; ++i)
shu.push_back(i);
he2.reserve(shu.size());
auto forward = shu.cbegin();
auto backward = shu.crbegin();
for (; forward != shu.cend() && backward != shu.crend(); ++forward, ++backward)
{
auto temp = *forward + *backward;
std::cout << *forward << ' ' << *backward << ' ' << temp << std::endl;
he2.push_back(temp);
}
std::copy(he2.cbegin(), he2.cend(), std::ostream_iterator<int>(std::cout, " "));
return 0;
}
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
const int N = 100;
int main()
{
std::vector<int> shu;
std::vector<int> he2;
for (int i = 1; i <= N; ++i)
shu.push_back(i);
auto size = shu.size();
he2.reserve(size);
for (decltype(size) index = 0, end = size; index < end; ++index)
{
auto temp = shu[index] + shu[--size];
std::cout << shu[index] << ' ' << shu[size] << ' ' << temp << std::endl;
he2.push_back(temp);
}
std::copy(he2.cbegin(), he2.cend(), std::ostream_iterator<int>(std::cout, " "));
return 0;
}