forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex3_24.cpp
More file actions
34 lines (28 loc) · 705 Bytes
/
Copy pathex3_24.cpp
File metadata and controls
34 lines (28 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <vector>
#include <iterator>
using std::vector;
using std::cout;
using std::endl;
using std::cin;
int main()
{
int i;
vector<int> ivec;
while (cin >> i) ivec.push_back(i);
if (ivec.empty()) {
cout << "input at least one integer." << endl;
return -1;
}
else if (ivec.size() == 1) {
cout << *ivec.begin() << " has no adjacent elements.";
}
for (auto it = ivec.begin(); it + 1 != ivec.end(); ++it)
cout << *it + *(it + 1) << " ";
cout << endl;
for (auto beg = ivec.begin(), end = ivec.end() - 1; beg <= end;
++beg, --end)
cout << *beg + *end << " ";
cout << endl;
return 0;
}