-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathExer03_20.cpp
More file actions
47 lines (47 loc) · 1.02 KB
/
Exer03_20.cpp
File metadata and controls
47 lines (47 loc) · 1.02 KB
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
41
42
43
44
45
46
47
// Tips: some situations must be considered carefully.
// For example: What if vector is null? What if vector has only one element?
#include <iostream>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
int main()
{
vector<int> v;
int i, j = 0;
while(cin >> i)
{
v.push_back(i);
}
if(v.size() > 0)
{
if(v.size() > 1)
{
while(j < v.size() - 1)
{
cout << v[j] + v[j + 1] << " ";
++j;
}
cout << endl;
j = 0;
while(j <= v.size() - 1 - j)
{
if(j < v.size() -1 - j)
cout << v[j] + v[v.size() - 1 - j] << " ";
else
cout << v[j];
++j;
}
cout << endl;
}
else
{
cout << v[j] << endl;
cout << v[j] << endl;
}
}
else
cout << "No elements!" << endl;
return 0;
}