Advertisement
totobac

Untitled

Jan 27th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int getGrid(int n)
  5. {
  6.     int counter = 0, sum = 0;
  7.     while (n != 0)
  8.     {
  9.         if (counter % 2 == 0)
  10.             sum += n % 10;
  11.         counter++;
  12.         n /= 10;
  13.     }
  14.     return sum;
  15. }
  16. int getMax(int a, int b, int c)
  17. {
  18.     if (a >= b && a >= c)
  19.         return a;
  20.     else if (b >= c)
  21.         return b;
  22.     else return c;
  23. }
  24. int getMin(int a, int b, int c)
  25. {
  26.     if (a <= b && a <= c)
  27.         return a;
  28.     else if (b <= c)
  29.         return b;
  30.     else return c;
  31. }
  32. bool isProgression(int a, int b, int c)
  33. {
  34.     int max = getMax(a, b, c);
  35.     int min = getMin(a, b, c);
  36.     int mid = (a + b + c - max - min);
  37.     int divider = max / mid;
  38.     if (min * divider == mid && mid * divider == max)
  39.         return 1;
  40.     else return 0;
  41. }
  42. int sumOfGrids(int a, int b, int c)
  43. {
  44.     int sum = 0;
  45.     for (size_t i = getMin(a,b,c); i <= getMax(a,b,c); i++)
  46.     {
  47.        sum += getGrid(i);
  48.     }
  49.     return sum;
  50. }
  51. int main()
  52. {
  53.     int a, b, c;
  54.     cout << "Enter a, b and c: ";
  55.     cin >> a >> b >> c;
  56.     if (isProgression(a, b, c))
  57.         cout << sumOfGrids(a, b, c);
  58.     else cout << "0";
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement