forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex3_20.cpp
39 lines (32 loc) · 758 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
#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;
}