题解 | #求最大连续bit数#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
方法1:python
while True: try: a = bin(int(input())) maxnumstr = a.count('1') maxnum = int(maxnumstr) num = 0 for i in range(maxnum): if '1' * (i + 1) in a: num = i + 1 else: break print(num) except: break
方法2:python
while True: try: n = int(input()) c = 0 m = 0 while n: if (n % 2): c += 1 if c > m: m = c else: c = 0 n = int(n/2) print(m) except: break
方法3: 最优解法
python
while True: try: number = int(input()) str_num = bin(number) print(len((max(str(str_num).replace("0b","").split("0"))))) except: break