fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6. int x, n = 0, nmax = 0, i = 0, k = 0, a[1000001], ost;
  7. scanf("%d", &x);
  8. x=abs(x);
  9. while (x >= 2) {
  10. ost = x % 2;
  11. a[k] = ost;
  12. x = x / 2;
  13. k++;
  14. }
  15. a[k] = x;
  16. for (i = k; i >= 0; i--) {
  17. if (a[i] == 1) {
  18. n = 1;
  19. i--;
  20. while (i >= 0 && a[i] == 1) {
  21. n++;
  22. i--;
  23. }
  24. if (n>nmax) nmax = n;
  25. n = 0;
  26. }
  27. }
  28. printf("%d", nmax);
  29. return 0;
  30. }
Success #stdin #stdout 0s 4532KB
stdin
-1023
stdout
10