目录

- #include
- #include
- #include
- using namespace std;
- void TEN_to_TWO(int x, vector<int>& data) { //10进制转换成二进制
- stack<int> s;
- while (x != 0) {
- int remainder = x % 2;//余数
- s.push(remainder);
- x /= 2;
- }
- while (!s.empty()) {
- data.push_back(s.top());
- s.pop();
- }
- }
- int main() {
- int x;
- cin >> x;
-
- vector<int>data;
- TEN_to_TWO(x, data);
- int left = 0, right = 0;
- bool mask = false;
- int _MAX = 0;
-
- while (right < data.size()) {
- while (right < data.size() && data[right] == 1) {
- if ( mask == false) {
- left = right;
- mask = true;
- }
- ++right;
- }
- if (data[right - 1] == 1)
- {
- _MAX = max(_MAX, right - left);
- mask = false;
- }
- ++right;
- }
- cout << _MAX;
- return 0;
- }
-