fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. for (string s; cin >> s; )
  11. {
  12. size_t l=0, n=s.length();
  13.  
  14. for (size_t q=0; q<n; ++q)
  15. s[q] -= '0';
  16.  
  17. vector <bool> res;
  18.  
  19. LOOP:
  20. {
  21. res.push_back(s[n-1] & 1);
  22.  
  23. for (int d=0, p; l<n; ++l)
  24. if (p=d?5:0, d=s[l]&1, (s[l]>>=1)+=p)
  25. {
  26. for (size_t q=l+1; q<n; ++q)
  27. p=d?5:0, d=s[q]&1, (s[q]>>=1)+=p;
  28.  
  29. goto LOOP;
  30. }
  31. }
  32.  
  33. copy(res.rbegin(), res.rend(), ostream_iterator<bool>(cout, ""));
  34. cout << endl;
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 15240KB
stdin
0
1
2
3
4
7
8
15
16
17
42
325
777
65000
65536
99999999999999999999999999999999999999999999999999999999999999999999999
stdout
0
1
10
11
100
111
1000
1111
10000
10001
101010
101000101
1100001001
1111110111101000
10000000000000000
11100111110100110100110001100100101010011100100001011101010001000110000011011011101111001010100001110001100101101011011000010110000110001010010010111101001000010110011111111111111111111111111111111111111111111111111111111111111111111111