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.empty() && 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
assignment
C++ Assignment..
derived_tempalte
Error with move capture of a const ref in a lambda function
MSVC lambda bug
VC++ latest rejects istream to nullptr comparison
hangman
a parameter pack
Iterate_Variac_Template
VS struct_member_name