#include #include #include #include int main() { int n = 0; std::array res{}; for (int counter = 0; counter < 2; ++counter) { std::cin >> n; std::vector> num1(n); num1[0] = std::vector(); char c; std::cin >> std::noskipws >> c; std::cin >> std::noskipws >> c; while (c != '\n') { num1[0].push_back(c == '#'); std::cin >> c; } int m = num1[0].size(); char ch; std::cin >> std::skipws; for (int row = 1; row < n; ++row) { num1[row] = std::vector(m); for (int col = 0; col < m; ++col) { std::cin >> ch; num1[row][col] = ch == '#'; } } int prevIdx = -1; for (int i = 0; i < n; ++i) { if (num1[0][i]) { prevIdx = i; } } int number = 1; for (int row = 1; row < n; ++row) { number = number << 1; //odd if (prevIdx - 1 >= 0 && num1[row][prevIdx - 1]) { number += 1; //add bit 1 on the lowest pos --prevIdx; continue; } ++prevIdx; } res[counter] = number; } int result = res[0] + res[1]; int offsetRight = 0; int offsetLeft = 0; int offset = 0; int rows = 0; std::queue rowHashPosition; rowHashPosition.push(offset); while(result != 1) { offset += result % 2 ? -1 : 1; result = result >> 1; offsetRight = offset < offsetRight ? offset : offsetRight; offsetLeft = offset > offsetLeft ? offset : offsetLeft; ++rows; rowHashPosition.push(offset); } offsetRight *= -1; std::cout << rows + 1 << std::endl; for (int i = 0; i <= rows; ++i) { int val = rowHashPosition.front(); rowHashPosition.pop(); for (int j = offsetRight; j <= offsetLeft; ++j) { if(val == j){ std::cout << '#'; continue; } std::cout << '.'; } std::cout << std::endl; } return 0; }