• + 0 comments
    #include <bits/stdc++.h>
    
    using namespace std;
    
    string ltrim(const string &);
    string rtrim(const string &);
    
    
    
    int main()
    {
        int bin[32];
        int concount[10];
        int n;
        int j = 0;
        int count =0;
        cin >> n;
        int x=0;
        
        while (n>0){
        
            int i = n%2;
            n = n/2;
            bin[j] = i;
            j++;
        }
        
        for (int i = j-1; i>=0; i--){
            if(bin[i] == 1){
                count += 1;
            }else if (bin[i] == 0 && count > 0){
                
                concount[x] = count;
                x++;
                count = 0;
            }
        }  
        // If there were trailing 1s
        if (count > 0) {
            concount[x] = count; // Store the last count of consecutive 1s
            x++;
        }
        int maxvalue = concount[0];
        // Output the counts of consecutive 1s
    
        for (int i = 0; i < x; i++) { // Use x to determine how many counts to print     
        if (concount[i] > maxvalue) {
            maxvalue = concount[i]; // Update maxValue if a larger value is found
            }
            
        }
        cout << maxvalue;
        cout << endl;
    
        return 0;
    }