Translate

Views

Sunday, July 28, 2019

Solution Kattis: Reversed Binary Numbers

https://open.kattis.com/problems/reversebinary
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<=b; i++)
using namespace std;

int n, d, x, ans;
int a[1000111];

void dec_bin_rev(){
 while(n>0){
  a[d]= n%2;
  n= n/2;
  d++;
 }
 d--;
 
}
void bin_dec(){
 x= d;
 FOR(i, 0, d){
  ans+= a[i]*pow(2,x);
  x--;
 }
 cout << ans;
}

int main(){
 cin >> n;
 dec_bin_rev();
 bin_dec();
}
Good luck! If you need help please leave a comment :) 

No comments: