lina_os

Untitled

Nov 2nd, 2024 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main(){
  9.  
  10. int t;
  11. cin >> t;
  12. while (t>0){t--;
  13. int n;
  14. string bin="";
  15. cin>>n;
  16. for(int i=n; i>0; i/=2){
  17. int a=i%2;
  18. bin=to_string(a)+bin; //converting to binary
  19. }
  20. string a="";
  21. int biN=stoi(bin);
  22. while(biN>0){
  23. if(biN%10)a="1"+a; //getting rid of zeros in the binary form
  24. biN/=10;
  25. }
  26. int N=stoi(a);
  27. int result=0;
  28. int poww=1;
  29. while(N>0){
  30. result+=poww; //converting to decimal
  31. poww*=2;
  32. N/=10;
  33. }cout<<result<<endl;
  34. }
  35. return 0;
  36. }
  37.  
  38.  
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment