-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1042.c
61 lines (55 loc) · 1.12 KB
/
1042.c
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
56
57
58
59
60
61
#include<stdio.h>
int main() {
int a[40];
int n,T,caseno=0,result=0;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
int tmp=0,c=0,flag=0;
while(n) {
a[c]=n&1;
n=n>>1;
c++;
}
//
// for(int i=0;i<c; i++){
// printf("%d ",a[i]);
// }puts("");
a[c]=0;
while(tmp<c) {
if(a[tmp]==1 && a[tmp+1]==0){
a[tmp]=0;
a[tmp+1]=1;
flag=1;
tmp++;
break;
}
tmp++;
}
if(flag){
int one=0;
for(int i=0;i<tmp; i++){
if(a[i])one++;
a[i]=0;
}
for(int i=0;i<one ; i++){
a[i]=1;
}
if(tmp==c)c++;
}
else{
a[c]=1;
c++;
}
// for(int i=0;i<c; i++){
// printf("%d ",a[i]);
// }puts("");
for(int i=c-1;i>=0 ; i--){
result=result<<1;
result=result|a[i];
}
printf("Case %d: %d\n",++caseno,result);
result=0;
}
return 0;
}