fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve()
  5. {
  6. int a, b, c;
  7. cin >> a >> b >> c;
  8.  
  9. double x[3];
  10. x[0] = a, x[1] = b, x[2] = c;
  11.  
  12. // double avg_d = (x[0] + x[1] + x[2]) / 3;
  13.  
  14. int avg = ceil((x[0] + x[1] + x[2]) / 3);
  15.  
  16. for (int i = 0; i < 3; i++)
  17. {
  18. if (x[i] > avg)
  19. x[i]--;
  20. else if (x[i] < avg)
  21. x[i]++;
  22. }
  23.  
  24. int ans = abs(x[0] - x[1]) + abs(x[0] - x[2]) + abs(x[1] - x[2]);
  25.  
  26. cout << ans << "\n";
  27. }
  28.  
  29. int main()
  30. {
  31. ios_base::sync_with_stdio(false);
  32. cin.tie(0);
  33.  
  34. int t;
  35. cin >> t;
  36.  
  37. while (t--)
  38. {
  39. solve();
  40. }
  41. }
Success #stdin #stdout 0s 5288KB
stdin
8
3 3 4
10 20 30
5 5 5
2 4 3
1 1000000000 1000000000
1 1000000000 999999999
3 2 5
3 2 6
stdout
0
36
0
0
1999999994
1999999994
2
4