Sort by

recency

|

2828 Discussions

|

  • + 0 comments

    Java

        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    
            int n = Integer.parseInt(bufferedReader.readLine().trim());
            
            StringBuffer strBase10 = new StringBuffer();
            int maxOnes = 0;
            int onesFound = 0;
            
            while(n>=1){
                double x = n;
                if(x%2==0){
                    strBase10.append("0");
                    if(onesFound>maxOnes){
                        maxOnes = onesFound;
                    }
                    onesFound = 0;
                }else{
                    onesFound++;
                    strBase10.append("1");
                }
                n = n/2;             
            }
            
            if(onesFound>maxOnes){
                maxOnes = onesFound;
            }
           
           System.out.println(maxOnes);
            
        }
    
  • + 0 comments

    JS:

    function main() {
        const n = parseInt(readLine().trim(), 10);
    
        console.log(n.toString(2).split('0').reduce((max, str) => Math.max(max, str.length), 0));
    }
    
  • + 0 comments

    c++: ` void d_b{int n){ int max= 0, count =0, rem =0; if (n == 0) cout << 0 << endl; else ( while (n>0){ rem = n%2; count = rem? count + 1: 0; max = (count> max) ? count:max; d/=2; } } cout << max << endl; } int main(){ ........... ......... d_b(n); return 0; }

  • + 0 comments
    import math
    import os
    import random
    import re
    import sys
    
    
    
    if __name__ == '__main__':
        n = int(input().strip())
        binary=bin(n)[2:]
        ones=binary.split('0')
        max_ones=max(len(group) for group in ones)
        print(max_ones)
    
  • + 0 comments

    c#

    int n = Convert.ToInt32(Console.ReadLine()); int count = 0; while (n > 0) { n = (n & (n >> 1)); count++; } Console.WriteLine(count);