fork download
  1. #include <iostream>
  2. #include<bitset>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int t;
  9. cin>>t;
  10. while(t--)
  11. {
  12. long n,count=0,sum=0;
  13. cin>>n;
  14. long a[21];
  15. long temp=n;
  16. while(temp!=0)
  17. {
  18. a[count]=temp%10;
  19. temp=temp/10;
  20. count++;
  21. }
  22. for(int i=0;i<count;i++)
  23. { sum=sum+a[i]*(pow(2,i));}
  24. sum=sum+1;
  25. long trm=sum;
  26. int b[20];
  27. int c1=0;
  28. while(trm!=0)
  29. {
  30. b[c1]=trm%2;
  31. trm=trm/2;
  32. c1++;
  33. }
  34. for(int i=c1-1;i>=0;i--)
  35. cout<<b[i];
  36. cout<<"\n";
  37.  
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 3300KB
stdin
6
10
100
110
1010
1
101010101010101010
stdout
11
101
111
1011
10
101000000000