fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. while(cin>>n && n!=-1)
  8. {
  9. if(n<=1)
  10. {
  11. cout<<n<<endl;
  12. continue;
  13. }
  14. int prev = n&1 , c = 1;
  15. n>>=1;
  16. int maxi = 0;
  17. while(n)
  18. {
  19. if((n&1) == prev && (n&1)) c++;
  20. else
  21. {
  22. prev= n&1;
  23. c=1;
  24. }
  25. maxi = max(maxi,c);
  26. n>>=1;
  27. }
  28. cout<<maxi<<endl;
  29. }
  30. }
Success #stdin #stdout 0s 15224KB
stdin
78
49
23
68
-1
stdout
3
2
3
1