fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. unsigned long powTable[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
  7.  
  8. int quasi_binary(int num, int tens)
  9. {
  10. int res,digit;
  11.  
  12. if(num == 0)
  13. {
  14. return 0;
  15. }
  16.  
  17. digit = num%10;
  18. num = num/10;
  19.  
  20. res = quasi_binary(num, tens+1);
  21.  
  22. if(digit)
  23. {
  24. cout << 1;
  25. return ((digit-1)*powTable[tens]+res);
  26. }
  27. else
  28. {
  29. cout << 0;
  30. return res;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. int n,k=-1,temp,digit;
  37. cin >> n;
  38.  
  39. //this loop calculates the value of k,as it needs to be printed first
  40. temp=n;
  41. while(temp)
  42. {
  43. digit = temp%10;
  44. temp = temp/10;
  45.  
  46. if(digit>k)
  47. k=digit;
  48. }
  49. cout << k << endl;
  50.  
  51. //print those k quasi-numbers
  52. while(n)
  53. {
  54. n = quasi_binary(n,0);
  55. cout << " ";
  56. }
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 3460KB
stdin
415
stdout
5
111 101 101 101 1