c++ - How can I combine code -
i wrote program, think not use 1 code 2 times.
problematic place here:
if (2 * cell_price > large_cell_price) { (int = 0; < parquet.size(); ++i) { (int j = 0; j < parquet[i].size(); ++j) { if (parquet[i][j] == '*') { if (j + 1 < parquet[i].size() && parquet[i][j + 1] == '*') { j++; sum += large_cell_price; } else { sum += cell_price; } } } } } else { (int = 0; < parquet.size(); ++i) { (int j = 0; j < parquet[i].size(); ++j) { if (parquet[i][j] == '*') { sum += cell_price; } } } }
i loop 2 times:
for (int = 0; < parquet.size(); ++i) { (int j = 0; j < parquet[i].size(); ++j) {
and can't combine it. how can it?
try code:
for (int = 0; < parquet.size(); ++i) { (int j = 0; j < parquet[i].size(); ++j) { if (parquet[i][j] == '*') { if (j + 1 < parquet[i].size() && parquet[i][j + 1] == '*' && (2 * cell_price > large_cell_price)) { j++; sum += large_cell_price; } else { sum += cell_price; } } } }
Comments
Post a Comment