You are viewing a single comment's thread. Return to all comments →
Bit shift version
#include <iostream> using namespace std; int main(){ int maxOnes = 0; int ones = 0; int lastBit = 1; int n; cin >> n; while (n != 0) { if (n & lastBit) { ones++; if (ones > maxOnes) { maxOnes = ones; } } else { ones = 0; } n = n >> 1; } cout << maxOnes; 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 →
Bit shift version