Untitled
unknown
plain_text
a year ago
1.7 kB
2
Indexable
Never
#include <iostream> #include <vector> using namespace std; int main() { int n = 3; vector<pair<int, int>> dirtyCells; char status[3][3] = { {'d', 'c', 'd'}, {'c', 'd', 'c'}, {'d', 'c', 'd'} }; int currentPositionRow = 0; // Starting row position of the vacuum cleaner int currentPositionCol = 0; // Starting column position of the vacuum cleaner // Identify dirty cells for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (status[i][j] == 'd') { dirtyCells.emplace_back(i + 1, j + 1); } } } // Simulate the cleaning process for (const auto& dirtyCell : dirtyCells) { int targetRow = dirtyCell.first - 1; int targetCol = dirtyCell.second - 1; // Move the vacuum cleaner left or right while (currentPositionCol != targetCol) { if (currentPositionCol < targetCol) { cout << "Move right" << endl; currentPositionCol++; } else { cout << "Move left" << endl; currentPositionCol--; } } // Move the vacuum cleaner up or down while (currentPositionRow != targetRow) { if (currentPositionRow < targetRow) { cout << "Move down" << endl; currentPositionRow++; } else { cout << "Move up" << endl; currentPositionRow--; } } // Clean the cell cout << "Clean cell at position (" << dirtyCell.first << ", " << dirtyCell.second << ")" << endl; status[targetRow][targetCol] = 'c'; } return 0; }