ProgMe

Untitled

Mar 30th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t;
  8. cin >> t;
  9. while (t--)
  10. {
  11. set <int> st;
  12. for (int i = 0; i < 3; i++)
  13. {
  14. int x;
  15. cin >> x;
  16. st.insert(x);
  17. }
  18. if (st.size() == 1)
  19. cout << 0;
  20. else if (st.size() == 2)
  21. cout << min(abs(*st.rbegin() - *st.begin() - 1), abs(*st.rbegin() - *st.begin() - 2)) * 2;
  22. else
  23. {
  24. set <int>::iterator it = st.begin();
  25. it++;
  26. if (*st.rbegin() - *it == 1 && *it - *st.begin() == 1)
  27. cout << 0;
  28. else if (*st.rbegin() - *it > 1)
  29. cout << abs(*st.rbegin() - *st.begin() - 2) + min(abs(*st.rbegin() - *it - 1), abs(*st.rbegin() - *it - 2)) + (*it - *st.begin());
  30. else
  31. cout << abs(*st.rbegin() - *st.begin() - 2) + min(abs(*it - *st.begin() - 1), abs(*it - *st.begin() - 2)) + (*st.rbegin() - *it);
  32. }
  33. cout << "\n";
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment