You are viewing a single comment's thread. Return to all comments →
I was doing the following, but this failed tests >2
110011011100 = [110] +1 (0) [110] +1 [1110] +2 (00) counted 4 consecutive ones. But the answer should be 3.
I really did not get the max of consecutive 1's... Clear now, let me change the code and post it here ;)
You will get 64 bit in two tests.
My code:
int main(){
int n, c, k, current_count, highest_count; current_count = 0; highest_count = 0; scanf("%d",&n); for (c = 63; c >= 0; c--) { k = n >> c; if (k & 1) { current_count++; // printf("1"); } else { // printf("0"); if (current_count > highest_count) highest_count = current_count; current_count = 0; } } // printf("\n"); printf("%d\n", highest_count); return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
I was doing the following, but this failed tests >2
110011011100 = [110] +1 (0) [110] +1 [1110] +2 (00) counted 4 consecutive ones. But the answer should be 3.
I really did not get the max of consecutive 1's... Clear now, let me change the code and post it here ;)
You will get 64 bit in two tests.
My code:
int main(){
}