纯C
#include <stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF) { int a[8]={0}; for(int i=0;i<8;i++) { if(n&(1<<i)) a[i] = 1; } int count=0; int max=0; for(int i=0;i<8;i++) { if(a[i]==1) count++; else count=0; max=max>count?max:count; } printf("%d\n",max); } }