11.2-HJ86 求最大连续bit数
求最大连续bit数_牛客题霸_牛客网 (nowcoder.com)
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int cur=0;
int max=0;
while(n!=0){
if((n&1)==1){
cur++;
if(cur>max){
max=cur;
}
}else{
cur=0;
}
n>>=1;//无符号右移-不管符号位,左边统一补0
}
System.out.println(max);
}
}
}