0
已解决
孙顾典
初级光能
初级光能
//孙顾典的代码
#include<bits/stdc++.h>
using namespace std;
string to (int a){
string s;
while (a != 0){
int x = a % 2;
s += x + '0';
a /= 2;
}
reverse(s.begin() , s.end());
return s;
}
int maxn = INT_MIN;
int main(){
int q;
cin >> q;
string a;
a = to(q);
a = "00" + a + " ";
int c = 1;
// cout << a << endl;
int l = a.find ('0');
if (l == string::npos){
cout << a.size();
return 0;
}
for (int i = 0; i < a.size(); i++){
if (a[i] == '0'){
a[i] = '1';
string p = a;
int k = 0;
for (int j = i - 1; j >= 0; j--){
if (a[j] == '0'){
k = j + 1;
break;
}
}
// cout << a << endl;
for (int j = k; j < p.size(); j++){
if (p[j] == '1' && p[j + 1] == '1'){
c ++;
} else {
break;
}
}
a[i] = '0';
} else {
maxn = max (maxn , c);
c = 1;
}
// cout << c << endl;
}
maxn = max (maxn , c);
cout << maxn;
return 0;
}