输入一个1字节长度的整型数,输出将其转换成二进制后的连续1的个数
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int n,i=0;
cin >> n;
int count[100] = { 0 };
if (n == 0)
cout << 0;
else if(n>0)
{
for (;n!=0;n = n / 2)
{
if (n % 2 == 1)
count[i]++;
else
i++;
}
}
else
{
int b = 256 - n;
for (;b != 0;b = b / 2)
{
if (b % 2 == 1)
{
count[i]++;
}
else
i++;
}
}
sort(count,count+10, cmp);
cout << count[0];
return 0;
}