-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_Vector_11.cpp
More file actions
52 lines (50 loc) · 1.14 KB
/
Copy path06_Vector_11.cpp
File metadata and controls
52 lines (50 loc) · 1.14 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
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,check=0;
vector<int> vec;
cin >> n;
for(int i=0;i<n;i++){
cin >> m;
if(check%2==0){
vec.insert(vec.begin(),m);
}else{
vec.push_back(m);
}
}
string input,inputstr;
getline(cin,input);
int start=0;
int count=0;
for(int i=0;i<input.length();i++){
if(input[i]==' '){
inputstr=input.substr(start,count);
count=0;
if((check%2==0) && (inputstr.length()>0)){
vec.insert(vec.begin(),stoi(inputstr));
}else{
if(inputstr.length()>0) vec.push_back(stoi(inputstr));
}
check++;
start=i+1;
}
else{
count++;
}
}
while(n!=-1){
cin >> n;
if(check%2==0){
vec.insert(vec.begin(),n);
}else{
if(inputstr.length()>0) vec.push_back(n);
}
check++;
}
cout << "[";
for(int i=0;i<vec.size();i++){
cout << vec[i] << ", ";
}
cout << "]";
return 0;
}