Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin >> t;
- while (t--)
- {
- set <int> st;
- for (int i = 0; i < 3; i++)
- {
- int x;
- cin >> x;
- st.insert(x);
- }
- if (st.size() == 1)
- cout << 0;
- else if (st.size() == 2)
- cout << min(abs(*st.rbegin() - *st.begin() - 1), abs(*st.rbegin() - *st.begin() - 2)) * 2;
- else
- {
- set <int>::iterator it = st.begin();
- it++;
- if (*st.rbegin() - *it == 1 && *it - *st.begin() == 1)
- cout << 0;
- else if (*st.rbegin() - *it > 1)
- cout << abs(*st.rbegin() - *st.begin() - 2) + min(abs(*st.rbegin() - *it - 1), abs(*st.rbegin() - *it - 2)) + (*it - *st.begin());
- else
- cout << abs(*st.rbegin() - *st.begin() - 2) + min(abs(*it - *st.begin() - 1), abs(*it - *st.begin() - 2)) + (*st.rbegin() - *it);
- }
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment