-
Notifications
You must be signed in to change notification settings - Fork 2
/
1042 - Secret Origins.cpp
55 lines (52 loc) · 1.1 KB
/
1042 - Secret Origins.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
int bin[32];
void getBin(int num)
{
int i=30;
while(num!= 0){
bin[i--] = num%2;
num/=2;
}
}
void makeBig()
{
int i = 30;
while(bin[i]!= 1) i--;
while(bin[i]!=0) i--;
swap(bin[i], bin[i+1]);
bool f = false;
int j = 30;
i++;
while(i<j){
while(bin[i]!=1 && i<=30)i++;
while(bin[j]!= 0 && j>=0) j--;
if(i<j)
swap(bin[i], bin[j]);
i++, j--;
}
}
int toDec()
{
int ret = 0;
int po = 0;
for(int i=30; i>=0; i--,po++){
ret = ret + (bin[i]*(1<<po));
}
return ret;
}
int main()
{
//freopen("out.txt","w",stdout);
int tc,n;
scanf("%d",&tc);
for(int t=1; t<=tc; t++){
scanf("%d",&n);
memset(bin, 0, sizeof bin);
getBin(n);
//printf("bits are: ");for(int i=0; i<=30; i++) cout<<bin[i]<<" "; cout<<endl;
makeBig();
//printf("after cg: ");for(int i=0; i<=30; i++) cout<<bin[i]<<" "; cout<<endl;
printf("Case %d: %d\n",t,toDec());
}
}