题目:https://codeforces.com/problemset/problem/1560/B
题解:
- 先对ab进行处理,使得a>b;
- 得到d=a-b和d2=2*d;
- 判断c和a是否超过d2;
- 而后再判断c>d和c<=d的情况
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main()
{
int t;
cin >> t;
while (t--)
{
int a, b, c;
cin >> a >> b >> c;
if (a < b)
swap(a, b);//a大于b
int d = a - b;
int d2 = 2 * d;
bool flag = 1;
if (c > d2 || a > d2)flag = 0;
if (flag)
{
if (c > d)
cout << c - d << endl;
else
cout << c + d << endl;
}
else
cout << -1 << endl;
}
}