fork(1) download
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string>
  7. using namespace std;
  8.  
  9. void solve(string &s, int n)
  10. {
  11. if(s.size() > 0)
  12. {
  13. solve(s.substr(0, n - 1), n - 1);
  14. cout << string(n - 1, ' ') << s << endl;
  15. }
  16. }
  17.  
  18. int main(){
  19. int n;
  20. cin >> n;
  21. solve(string(n, '#'), n);
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
compilation info
prog.cpp: In function 'void solve(std::string&, int)':
prog.cpp:13:23: error: invalid initialization of non-const reference of type 'std::string& {aka std::basic_string<char>&}' from an rvalue of type 'std::basic_string<char>'
         solve(s.substr(0, n - 1), n - 1);
                       ^
prog.cpp:9:6: note:   initializing argument 1 of 'void solve(std::string&, int)'
 void solve(string &s, int n)
      ^
prog.cpp: In function 'int main()':
prog.cpp:21:28: error: invalid initialization of non-const reference of type 'std::string& {aka std::basic_string<char>&}' from an rvalue of type 'std::string {aka std::basic_string<char>}'
     solve(string(n, '#'), n);
                            ^
prog.cpp:9:6: note:   initializing argument 1 of 'void solve(std::string&, int)'
 void solve(string &s, int n)
      ^
stdout
Standard output is empty