SHARE
TWEET

assignment 4

a guest Mar 22nd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. void f(int n)
  8. {
  9.     vector<int> v;
  10.     for(int i=0;(1<<i)<=n;i++)
  11.     {
  12.         v.push_back((bool)(n&(1<<i)));
  13.     }
  14.     v.push_back(0);
  15.     for(int i=0;i+1<v.size();i++)
  16.     {
  17.         if(v[i]==2)
  18.         {
  19.             v[i]=0;
  20.             v[i+1]+=1;
  21.         }
  22.         if(v[i]==1 && v[i+1]==1)
  23.         {
  24.             v[i]=-1;
  25.             v[i+1]=0;
  26.             v[i+2]+=1;
  27.         }
  28.     }
  29.     for(int i=0;i<v.size();i++)
  30.     {
  31.         if(i+1==v.size())
  32.         {
  33.             if(v[i]!=0)cout<<v[i]<<' ';
  34.         }
  35.         else cout<<v[i]<<' ';
  36.     }
  37. }
  38. int main()
  39. {
  40.     int n;
  41.     cin>>n;
  42.     f(n);
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top