Advertisement
H-a-y-K

Untitled

Nov 30th, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int evens_count(long long int num)
  4. {
  5.     int count = 0;
  6.     int prev_checked = -1;
  7.     bool counting = false;
  8.  
  9.     while (num >= 0)
  10.     {
  11.         if (prev_checked % 2 == 0)
  12.         {
  13.             if (num != 0 && num % 2 == 0)
  14.             {
  15.                 counting = true;
  16.                 count++;
  17.             }
  18.             else if (counting)
  19.             {
  20.                 counting = false;
  21.                 count++;
  22.             }
  23.         }
  24.         if (num == 0)
  25.             break;
  26.  
  27.         prev_checked = num % 10;
  28.         num /= 10;
  29.     }
  30.  
  31.     return count;
  32. }
  33.  
  34. int main() {
  35.   std::cout << evens_count(22);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement