Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- #include <queue>
- const int size = 10;
- std::array<std::array<char, size>, size> readInput() {
- std::array<std::array<char, size>, size> input;
- for (auto& row : input) {
- for (auto& elem : row) {
- std::cin >> elem;
- }
- }
- return input;
- }
- void findRustPoints(std::array<std::array<char, size>, size>& input, std::queue<std::pair<int, int>>& currentRust) {
- for (int i = 0; i < size; ++i) {
- for (int j = 0; j < size; ++j) {
- if (input[i][j] == '!') {
- currentRust.push(std::make_pair(i, j));
- }
- }
- }
- }
- void makeOneMove(std::array<std::array<char, size>, size>& input, std::queue<std::pair<int, int>>& currentRust) {
- while (!currentRust.empty()) {
- std::pair<int, int> currentRustPair = currentRust.front();
- int row = currentRustPair.first;
- int col = currentRustPair.second;
- if (row - 1 >= 0) {
- if (input[row - 1][col] != '#') {
- input[row - 1][col] = '!';
- }
- }
- if (row + 1 < size) {
- if (input[row + 1][col] != '#') {
- input[row + 1][col] = '!';
- }
- }
- if (col - 1 >= 0) {
- if (input[row][col - 1] != '#') {
- input[row][col - 1] = '!';
- }
- }
- if (col + 1 < size) {
- if (input[row][col + 1] != '#') {
- input[row][col + 1] = '!';
- }
- }
- currentRust.pop();
- }
- }
- void processRusting(std::array<std::array<char, size>, size>& input, std::queue<std::pair<int, int>>& currentRust, int& rustCount) {
- for (int i = 0; i < rustCount; ++i) {
- findRustPoints(input, currentRust);
- makeOneMove(input, currentRust);
- }
- }
- void printSolution(std::array<std::array<char, size>, size>& input) {
- for (auto& row : input) {
- for (auto& elem : row) {
- std::cout << elem;
- }
- std::cout << std::endl;
- }
- }
- int main() {
- std::array<std::array<char, size>, size> input = readInput();
- int rustCount = 0;
- std::cin >> rustCount;
- std::queue<std::pair<int, int>> currentRust;
- processRusting(input, currentRust, rustCount);
- printSolution(input);
- }
Advertisement
Add Comment
Please, Sign In to add comment