fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n;
  10. double x1, y1, r1, x2, y2, r2;
  11. double d,l;
  12. cin >> n;
  13. cout.setf(ios::fixed);
  14. cout.precision(2);
  15. for (int i = 0; i < n; i++)
  16. {
  17. cin >> x1; cin >> y1; cin >> r1;
  18. cin >> x2; cin >> y2; cin >> r2;
  19. d = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  20. if (r1 + r2 <= d) //okregi rozlaczne/styczne
  21. l = 0;
  22. else if (d > abs(r1 - r2) && d < r1 + r2)//okregi przecinaja sie
  23. l = r1 + r2 - d;
  24. else if (d <= abs(r1 - r2)) //jeden w drugim
  25. {
  26. if (r1 < r2)
  27. l = 2 * r1;
  28. else
  29. l = 2 * r2;
  30. }
  31. cout << l << endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5516KB
stdin
6
3 3 3
3 -1 4
-3 -3 3
-1 2 5
3 3 2
-3 -3 1
5 5 10
13 5 4
10 5 2
5 10 3
0 0 10
1 1 100
stdout
3.00
2.61
0.00
6.00
0.00
20.00