#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #define db(a) cout << #a << " = " << a << endl #define foreach(it, l) for ( typeof(l.begin()) it = l.begin(); it != l.end(); it++) #define dbl(i, a) cout << "[" << i << "]" << " = "<< a << ", "; #define listar(lista) for(int i = 0; i < lista.size(); i++) { dbl(i, lista[i]);} cout << endl; using namespace std; int main() { /*freopen("perm.in", "r", stdin); freopen("perm.out", "w", stdout);*/ #ifdef dennisbot freopen("in.in", "r", stdin); #endif int n; while (scanf("%d", &n) != EOF) { if (n == 0) { break; } string num = ""; for (int i = 0; i < 32; i++) { if (n >> i & 1) { num += "1"; } else num += "0"; } num = num.substr(0, num.find_last_of("1") + 1); int t = 1, res = 0; for (int i = num.size() - 1; i >= 0; i--) { res += (num[i] - 48) * t; t *= 2; } printf("%d\n", res); } return 0; }
viernes, 30 de marzo de 2012
2841. Bitwise Reverse, tju
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario