InnaSibirova

ДЗ3, №5

Nov 8th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <cmath>
  4. using namespace std;
  5. int main() {
  6.  
  7.     int a, b, c, d, g, i = 0, x1, x2, x3, y1, y2, y3;
  8.     cin >> a;
  9.     c = 0;
  10.     g = 0;
  11.     while(a) {
  12.         b = a % 2;
  13.         a /= 2;
  14.         c = c * 10 + b;
  15.         g++;
  16.        
  17.     }
  18.     a = 0;
  19.     if(g < 3) {
  20.         cout << 0;
  21.         exit(0);
  22.     }
  23.     for(d = 0; (d + 2) < g; d++) {
  24.     x1 = c / pow(10, d);
  25.     x2 = c / pow(10, d + 1);
  26.     x3 = c / pow(10, d + 2);
  27.     y1 = x1 % 10;
  28.     y2 = x2 % 10;
  29.     y3 = x3 % 10;
  30.     if(y1 == 1 && y2 == 1 && y3 == 1) {
  31.         ++i;
  32.     }
  33. }
  34. cout << i;
  35. }
Add Comment
Please, Sign In to add comment