vlatkovski

Skakulci

Jun 7th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int a, b, c, t;
  7.     cin >> a >> b >> c;
  8.  
  9.     //make the numbers so a < b < c
  10.     if (a > b) { t = a; a = b; b = t; }
  11.     if (a > c) { t = a; a = c; c = t; }
  12.     if (b > c) { t = b; b = c; c = t; }
  13.  
  14.     int n = 0;
  15.  
  16.     while (a + 1 != b || b + 1 != c) {
  17.         if (b - a <= c - b) { //pomal e intervalot megju a i b
  18.             //a odi megju b i c
  19.             t = c - 1; //nova vrednost na a
  20.             a = b;
  21.             b = t;
  22.         } else { //pomal e intervalot megju b i c
  23.             //c odi megju a i b
  24.             t = a + 1; //nova vrednost na c
  25.             c = b;
  26.             b = t;
  27.         }
  28.         n++;
  29.     }
  30.  
  31.  
  32.     cout << n;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment