|
|
@ -45,13 +45,13 @@ Result Day05::Task2() { |
|
|
|
vector<Stack> Day05::parseStacks(){ |
|
|
|
vector<Stack> Day05::parseStacks(){ |
|
|
|
vector<Stack> parsed; |
|
|
|
vector<Stack> parsed; |
|
|
|
|
|
|
|
|
|
|
|
int endIndex = splitIndex(); |
|
|
|
size_t endIndex = splitIndex(); |
|
|
|
string numberLine = input[endIndex - 1]; |
|
|
|
string numberLine = input[endIndex - 1]; |
|
|
|
int stackCount = atoi(&numberLine.at(numberLine.size() - 2)); |
|
|
|
int stackCount = atoi(&numberLine.at(numberLine.size() - 2)); |
|
|
|
for (int i = 0; i < stackCount; i++){ |
|
|
|
for (int i = 0; i < stackCount; i++){ |
|
|
|
parsed.emplace_back(); |
|
|
|
parsed.emplace_back(); |
|
|
|
int index = 1 + 4 * i; |
|
|
|
int index = 1 + 4 * i; |
|
|
|
for (int line = endIndex - 2; line >= 0 && input[line].size() > index && input[line][index] != ' '; line--){ |
|
|
|
for (size_t line = endIndex - 2; input[line].size() > index && input[line][index] != ' '; line--){ |
|
|
|
Crate crate = input[line][index]; |
|
|
|
Crate crate = input[line][index]; |
|
|
|
parsed[i].push_back(crate); |
|
|
|
parsed[i].push_back(crate); |
|
|
|
} |
|
|
|
} |
|
|
@ -63,9 +63,9 @@ vector<Stack> Day05::parseStacks(){ |
|
|
|
vector<Move> Day05::parseMoves() { |
|
|
|
vector<Move> Day05::parseMoves() { |
|
|
|
vector<Move> parsed; |
|
|
|
vector<Move> parsed; |
|
|
|
|
|
|
|
|
|
|
|
int startIndex = splitIndex() + 1; |
|
|
|
size_t startIndex = splitIndex() + 1; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = startIndex; i < input.size(); i++){ |
|
|
|
for (size_t i = startIndex; i < input.size(); i++){ |
|
|
|
string line = input[i]; |
|
|
|
string line = input[i]; |
|
|
|
size_t fromIndex = line.find(" from"); |
|
|
|
size_t fromIndex = line.find(" from"); |
|
|
|
int count = stoi(line.substr(5, fromIndex - 5)); |
|
|
|
int count = stoi(line.substr(5, fromIndex - 5)); |
|
|
@ -77,8 +77,8 @@ vector<Move> Day05::parseMoves() { |
|
|
|
return parsed; |
|
|
|
return parsed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int Day05::splitIndex(){ |
|
|
|
size_t Day05::splitIndex(){ |
|
|
|
auto iter = std::find_if(input.begin(), input.end(), [](const string& element){return element == "";}); |
|
|
|
auto iter = std::find_if(input.begin(), input.end(), [](const string& element){return element.empty();}); |
|
|
|
return iter - input.begin(); |
|
|
|
return iter - input.begin(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|