Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
algorithm_1
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <iostream> #include<string> using namespace std; string f(int n,int x) { string f1,f2; int a = n-x; int b = x+1; int c = a/b; int d = a%b; int e = 0; if((n/2)==x&&n%x==0) e = 2; else if ((n-1)/2<x) e = 1; else e = 0; if(d!=0) { if (e==1) { f2 = f(n,n-x); for (int i=0;i<f2.length();i++) { if (f2[i]=='0') f2[i] = '1'; else f2[i] = '0'; } return (f2); } else if (e==2) { f2 = f(n+1,x); f2.erase(f2.length()-1,1); return (f2); } else f2 = f(b,d); } for(int i=0;i<b;i++) { for(int l=0;l<c;l++) { f1 = f1+"0"; } if(f2[i]=='1') f1 = f1+"0"; if(i!=b-1) f1 = f1+"1"; } return(f1); }; int main() { for (int i=3;i<50;i++) { for (int l=1;l<=i;l++) { cout <<f(i,l)<< endl; } } return 0; }
run
|
edit
|
history
|
help
0
C++ move/copy constructor and assignment demo
typeid VC++
#21
#9
constexpr internal error
Matrix paths right-down only, going through XY
Postfix side effect returning 2
Memory example
Unicode_write2file
Error log b is an undeclared identifier...