-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ex3_20.cpp
40 lines (33 loc) · 836 Bytes
/
ex3_20.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
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
using std::vector;
using std::cout;
using std::endl;
using std::cin;
int main()
{
vector<int> ivec;
int i;
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[0] << " don't have any adjacent elements.";
}
else {
for (decltype(ivec.size()) i = 0; i != ivec.size() - 1; ++i)
cout << ivec[i] + ivec[i + 1] << " ";
}
cout << endl;
decltype(ivec.size()) size = ivec.size();
if (size % 2 != 0)
size = size / 2 + 1;
else
size /= 2;
for (decltype(ivec.size()) i = 0; i != size; ++i)
cout << ivec[i] + ivec[ivec.size() - i - 1] << " ";
cout << endl;
return 0;
}