新手解法
2026-04-06 10:57:29
发布于:北京
6阅读
0回复
0点赞
比起一楼的题解,我这个有点降智,谨慎观看,上代码
#include <bits/stdc++.h>
#include <ostream>
using namespace std ;
string s;
int main () {
long long n ;
cin >> n ;
long long x = n ;
while(x) {
int sum = x % 2 ;
s = (char)(sum + '0') + s ;
x /= 2 ;
}
int ans ;
int maxx = 0 ;
ans = 0 ;
for(int i = 0 ; i < s.size() ; i++) {
if(s[i] == '1') {
ans++ ;
}
if(s[i] == '0') {
maxx = max(maxx , ans) ;
ans *= 0 ;
}
}
maxx = max(maxx , ans) ;
cout << maxx ;
return 0 ;
}
这里空空如也

有帮助,赞一个