#include #include #include int main() { int ruleDecimal; int generationCount; std::string ahoj; std::cin >> ruleDecimal >> generationCount; std::getline(std::cin, ahoj); std::bitset<8> rule(ruleDecimal); std::vector firstGeneration; std::string firstGenerationString; std::cin >> firstGenerationString; std::getline(std::cin, ahoj); firstGeneration.push_back(false); for (const auto& c : firstGenerationString) { if (c == '.') { firstGeneration.push_back(false); } else if (c == 'X') { firstGeneration.push_back(true); } } firstGeneration.push_back(false); for (int i = 0; i < generationCount + 1; i++) { std::vector nextGeneration; nextGeneration.push_back(false); for (int j = 1; j < firstGenerationString.length() + 1; j++) { int index = (firstGeneration[j - 1] << 2) + (firstGeneration[j] << 1) + (firstGeneration[j + 1]); nextGeneration.push_back(rule[index]); } nextGeneration.push_back(false); if (i == 0) { firstGeneration = nextGeneration; continue; } for (int j = 1; j < firstGenerationString.length() + 1; j++) { if (firstGeneration[j]) { std::cout << "X"; } else { std::cout << "."; } } std::cout << std::endl; firstGeneration = nextGeneration; } return 0; }