fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. void c(int x,string r){int i,t=0,s=r.size();if(s<8){if(r[0]>48){for(i=0;i<s;i++)t+=(r[s-i-1]-48)*1<<i;if(t==x)cout<<r<<" ";}for(char n=48;n<51;n++)c(x,r+n);}}
  8.  
  9. int main()
  10. {
  11. int xs[] = { 2, 9, 10, 23, 37 };
  12. for (int x : xs)
  13. {
  14. string t;
  15. cout << x << ": ";
  16. c(x, t);
  17. cout << endl;
  18. }
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2: 10 2 
9: 1001 121 201 
10: 1002 1010 122 202 210 
23: 10111 2111 
37: 100021 100101 11221 12021 12101 20021 20101