mirror of
https://github.com/szymon-jozef/advent_of_code_2025.git
synced 2026-09-07 12:10:41 +02:00
minor optimalization
This commit is contained in:
@@ -21,26 +21,24 @@ vector<string> get_input(const string &FILE_NAME) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int count_rows(const vector<string> &input) {
|
|
||||||
int count = 0;
|
|
||||||
for (string row : input) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<vector<string>> process_input(const vector<string> &input) {
|
vector<vector<string>> process_input(const vector<string> &input) {
|
||||||
string new_column = "";
|
string new_column = "";
|
||||||
|
|
||||||
vector<vector<string>> result;
|
vector<vector<string>> result;
|
||||||
vector<string> group;
|
vector<string> group;
|
||||||
|
|
||||||
char expresion = ' ';
|
char expresion = ' ';
|
||||||
|
const int row_count = input.size();
|
||||||
|
const int column_count = input.front().size();
|
||||||
|
|
||||||
|
group.reserve(row_count + 1);
|
||||||
|
new_column.reserve(row_count);
|
||||||
|
|
||||||
// for every row from behind
|
// for every row from behind
|
||||||
for (int i = input[0].length() - 1; i >= 0; i--) {
|
for (int i = column_count - 1; i >= 0; i--) {
|
||||||
|
|
||||||
// for every column
|
// for every column
|
||||||
for (int j = 0; j < count_rows(input); j++) {
|
for (int j = 0; j < row_count; j++) {
|
||||||
|
|
||||||
char symbol = input[j][i];
|
char symbol = input[j][i];
|
||||||
if (symbol == ' ') {
|
if (symbol == ' ') {
|
||||||
@@ -55,7 +53,7 @@ vector<vector<string>> process_input(const vector<string> &input) {
|
|||||||
}
|
}
|
||||||
if (new_column != "") {
|
if (new_column != "") {
|
||||||
group.push_back(new_column);
|
group.push_back(new_column);
|
||||||
new_column = "";
|
new_column.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expresion != ' ') {
|
if (expresion != ' ') {
|
||||||
|
|||||||
Reference in New Issue
Block a user