Submission details
Task:Fraktaali
Sender:removed859
Submission time:2017-10-10 21:31:28 +0300
Language:C++
Status:SKIPPED

Code

#include <iostream>
#include <string>
#include <vector>


// for inverting strings consisting of # and .
std::string q(std::string s) {
  for (char & c : s) {
    if (c == '#') { c = '.'; }
    else if (c == '.') { c = '#'; }
  }
  return s;
}


void f(int n) {
  std::vector<std::string> v = {"#"};
  n--; // the loop needs to run once less than the number of the fractal; 1 is just the starting "#"
  for (; n > 0; --n) {
    const unsigned l = v.size();
    // iterate over every item in v
    for (unsigned i = 0; i < l; i++) {
      v.push_back(v.at(i) + q(v.at(i))); // add the current line and the current line inverted to the end of the vector
      v.at(i) += v.at(i); // double the current line
    }
  }
  for (auto & s : v) {
    std::cout << s << '\n';
  }
}


int main() {
  int n;
  std::cin >> n;

  f(n);

  std::cin >> n;
  return 0;
}