Finished aoc day 5

This commit is contained in:
2022-12-10 17:20:45 +01:00
parent 4418726f2c
commit b89181c366

View File

@@ -69,13 +69,28 @@ int main(){
int number_of_moves, source, target; int number_of_moves, source, target;
tie(number_of_moves, source, target) = command; tie(number_of_moves, source, target) = command;
// For part 1 use this:
// while(number_of_moves > 0){
// char crate = crate_stacks[source - 1].top();
// crate_stacks[source - 1].pop();
// crate_stacks[target - 1].push(crate);
// number_of_moves--;
// }
vector<char> crates;
while(number_of_moves > 0){ while(number_of_moves > 0){
char crate = crate_stacks[source - 1].top(); char crate = crate_stacks[source - 1].top();
crate_stacks[source - 1].pop(); crate_stacks[source - 1].pop();
crate_stacks[target - 1].push(crate); crates.push_back(crate);
number_of_moves--; number_of_moves--;
} }
for(int i = crates.size() - 1; i >= 0; i--){
crate_stacks[target - 1].push(crates[i]);
}
} }
// Print answer // Print answer