fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );
  8.  
  9. int N; cin >> N; stack< int > bits;
  10.  
  11. for( int k = 0; N != 0; k++ )
  12. {
  13. int bit = ( N & 1 );
  14.  
  15. bits.push( bit ), N >>= 1;
  16.  
  17. if ( ( k & 1 ) and bit )
  18. N++;
  19. }
  20.  
  21. if ( bits.empty() )
  22. cout << 0;
  23. else
  24. while( !bits.empty() )
  25. cout << bits.top(), bits.pop();
  26. }
Success #stdin #stdout 0s 4176KB
stdin
123456789
stdout
11000101011001101110100010101