Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- int main(){
- int t;
- cin >> t;
- while (t>0){t--;
- int n;
- string bin="";
- cin>>n;
- for(int i=n; i>0; i/=2){
- int a=i%2;
- bin=to_string(a)+bin; //converting to binary
- }
- string a="";
- int biN=stoi(bin);
- while(biN>0){
- if(biN%10)a="1"+a; //getting rid of zeros in the binary form
- biN/=10;
- }
- int N=stoi(a);
- int result=0;
- int poww=1;
- while(N>0){
- result+=poww; //converting to decimal
- poww*=2;
- N/=10;
- }cout<<result<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment