https://www.hackerrank.com/challenges/30-binary-numbers/problem
*/
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main(){
int n;
cin >> n;
int count = 0, max = 0;
while(n){ // Repetition will be stopped when n is 0.
if(n%2 == 1) {
count++;
if(count > max) {
max = count; //If count is bigger than max, store the number.
}
} else {
count = 0; //when the result of n%2 is 0, It's not consecutive anymore
}
n /= 2;
}
cout << max;
return 0;
}
댓글 없음:
댓글 쓰기