Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Permute
std::current_exception makes a copy
Spirit Lex combining token_id's with semantic actions
Workaround for https://github.com/Project-OSRM/osrm-backend/pull/4385
constmsvc
C string literal
#27
#30.3
iota_30-Seconds-of-C++
Dynamically sized array at end of struct
Please log in to post a comment.