Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int getGrid(int n)
- {
- int counter = 0, sum = 0;
- while (n != 0)
- {
- if (counter % 2 == 0)
- sum += n % 10;
- counter++;
- n /= 10;
- }
- return sum;
- }
- int getMax(int a, int b, int c)
- {
- if (a >= b && a >= c)
- return a;
- else if (b >= c)
- return b;
- else return c;
- }
- int getMin(int a, int b, int c)
- {
- if (a <= b && a <= c)
- return a;
- else if (b <= c)
- return b;
- else return c;
- }
- bool isProgression(int a, int b, int c)
- {
- int max = getMax(a, b, c);
- int min = getMin(a, b, c);
- int mid = (a + b + c - max - min);
- int divider = max / mid;
- if (min * divider == mid && mid * divider == max)
- return 1;
- else return 0;
- }
- int sumOfGrids(int a, int b, int c)
- {
- int sum = 0;
- for (size_t i = getMin(a,b,c); i <= getMax(a,b,c); i++)
- {
- sum += getGrid(i);
- }
- return sum;
- }
- int main()
- {
- int a, b, c;
- cout << "Enter a, b and c: ";
- cin >> a >> b >> c;
- if (isProgression(a, b, c))
- cout << sumOfGrids(a, b, c);
- else cout << "0";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement