-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcraneProb.cpp
90 lines (70 loc) · 1.95 KB
/
craneProb.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include<vector>
#include<bits/stdc++.h>
// #include<stdio.h>
int maxnum ;
std::vector<long long> initConfig;
std::vector<int> instructions;
bool picked_up = false;
long long* end;
long long* begin;
long long* ptrn;
void doOp(long long* &ptr,int op){
// int* end =
// int * begin =
switch(op){
case 1: // move left
if (ptr != begin){
ptr--;
}
break;
case 2: //move right
if (ptr != end){
ptr++;
}
break;
case 3: //pick up
if (*ptr>0 && !picked_up) {
*ptr = *ptr -1;
picked_up = true; }
break;
case 4: //pick
if (*ptr < maxnum && picked_up) {
*ptr = *ptr +1;
picked_up = false;
}
break;
// default:
// std::cout<<"lol";
}
}
int main(){
int n;
long long maxheight;
std::cin >> n >> maxheight;
for (int i = 0; i< n; i++){
int temp_ss ;
std::cin >>temp_ss;
initConfig.push_back(temp_ss);
}
maxnum = maxheight;
while (1){
int temp_s;
std::cin>>temp_s;
if (temp_s==0){
break;
}
else {
instructions.push_back(temp_s);
}
}
begin = &initConfig[0];
end = &initConfig[initConfig.size()-1];
ptrn = begin;
for (int j = 0 ; j < instructions.size();j++){
doOp(ptrn,instructions[j]);
}
for (int j = 0 ; j < initConfig.size();j++){
std::cout << initConfig[j]<<" ";
}
}