fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // generuje kolejną linię Cantora
  6. string nextCantor(string line) {
  7. string newLine = "";
  8.  
  9. for (char c : line) {
  10. if (c == '#')
  11. newLine += "###";
  12. else
  13. newLine += " ";
  14. }
  15.  
  16. int n = newLine.length();
  17. int third = n / 3;
  18.  
  19. // usuwamy środkową część
  20. for (int i = third; i < 2 * third; i++) {
  21. newLine[i] = ' ';
  22. }
  23.  
  24. return newLine;
  25. }
  26.  
  27. int main() {
  28. int stopien = 3; // ← tutaj masz na stałe stopień 3
  29.  
  30. string line = "#";
  31. cout << line << endl;
  32.  
  33. for (int i = 1; i <= stopien; i++) {
  34. line = nextCantor(line);
  35. cout << line << endl;
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
#
# #
###   ###
#########         #########