forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.24.cpp
30 lines (25 loc) · 716 Bytes
/
3.24.cpp
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
#include <iostream>
#include <vector>
void sum_adjacent(const std::vector<int> &v) {
if (v.size() < 2)
return;
for (auto it = v.cbegin(); it != v.cend() - 1; ++it)
std::cout << *it + *(it + 1) << '\t';
std::cout << std::endl;
}
void sum_symmetric(const std::vector<int> &v) {
// If the vector has odd size, element in the middle will add to itself.
auto mid = v.cbegin() + (v.cend() - v.cbegin() + 1) / 2;
for (auto it = v.cbegin(); it != mid; ++it)
std::cout << *it + *(v.cend() - 1 - (it - v.cbegin())) << '\t';
std::cout << std::endl;
}
int main() {
std::vector<int> iv;
int i;
while (std::cin >> i)
iv.push_back(i);
sum_adjacent(iv);
sum_symmetric(iv);
return 0;
}