diff --git a/6th_day/2/main.cpp b/6th_day/2/main.cpp index 0a3d982..11dda75 100644 --- a/6th_day/2/main.cpp +++ b/6th_day/2/main.cpp @@ -21,26 +21,24 @@ vector get_input(const string &FILE_NAME) { return result; } -int count_rows(const vector &input) { - int count = 0; - for (string row : input) { - count++; - } - - return count; -} - vector> process_input(const vector &input) { string new_column = ""; + vector> result; vector group; + 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 (int i = input[0].length() - 1; i >= 0; i--) { + for (int i = column_count - 1; i >= 0; i--) { // 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]; if (symbol == ' ') { @@ -55,7 +53,7 @@ vector> process_input(const vector &input) { } if (new_column != "") { group.push_back(new_column); - new_column = ""; + new_column.clear(); } if (expresion != ' ') {