fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // funkcja generująca kolejną linię
  6. string nextCantor(const string& line) {
  7. string result = line;
  8.  
  9. for (int i = 0; i < line.length(); i++) {
  10. if (line[i] == '#') {
  11. int len = result.length() / line.length();
  12. }
  13. }
  14.  
  15. int n = line.length();
  16. string newLine = "";
  17.  
  18. for (int i = 0; i < n; i++) {
  19. if (line[i] == '#') {
  20. newLine += "###";
  21. } else {
  22. newLine += " ";
  23. }
  24. }
  25.  
  26. // usuwamy środkową trzecią część
  27. int size = newLine.length();
  28. int third = size / 3;
  29.  
  30. for (int i = third; i < 2 * third; i++) {
  31. newLine[i] = ' ';
  32. }
  33.  
  34. return newLine;
  35. }
  36.  
  37. int main() {
  38. int stopien;
  39. cout << "Podaj stopien (np. 3 lub 6): ";
  40. cin >> stopien;
  41.  
  42. if (stopien < 0 || stopien > 6) {
  43. cout << "Podaj stopien 0-6!" << endl;
  44. return 0;
  45. }
  46.  
  47. string line = "#";
  48.  
  49. cout << line << endl;
  50.  
  51. for (int i = 1; i <= stopien; i++) {
  52. line = nextCantor(line);
  53. cout << line << endl;
  54. }
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Podaj stopien (np. 3 lub 6): Podaj stopien 0-6!