fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const double eps = 1e-9;
  5.  
  6. bool isEqual(double a, double b) {
  7. return fabs(a-b) < eps;
  8. }
  9.  
  10. bool isLessOrEqual(double a, double b) {
  11. return (isEqual(a, b) || a < b);
  12. }
  13.  
  14. bool isLess(double a, double b) {
  15. return (a < b && !isEqual);
  16. }
  17.  
  18. struct point {
  19. double x, y;
  20. // constructor
  21. point() {
  22. // cout << "Constructor kosong" << endl;
  23. }
  24. point(double _x, double _y) {
  25. // cout << "Constructor dgn 2 double" << endl;
  26. x = _x;
  27. y = _y;
  28. }
  29. double euclidean(point other) {
  30. return sqrt((x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));
  31. }
  32. double manhattan(point other) {
  33. return abs(x-other.x) + abs(y-other.y);
  34. }
  35. };
  36.  
  37. const double PI = acos(-1);
  38.  
  39. struct circle {
  40. point center;
  41. double radius;
  42. circle() {}
  43. circle(point _center, double _radius) {
  44. center = _center;
  45. radius = _radius;
  46. }
  47. double area() {
  48. return PI*radius*radius;
  49. }
  50. bool isTouching(circle other) {
  51. double distance = center.euclidean(other.center);
  52. return isLessOrEqual(distance, radius+other.radius);
  53. }
  54. };
  55.  
  56. int main() {
  57. circle l1, l2;
  58. cin >> l1.center.x >> l1.center.y >> l1.radius;
  59. cin >> l2.center.x >> l2.center.y >> l2.radius;
  60. if(l1.isTouching(l2))
  61. cout << "bersentuhan" << endl;
  62. else
  63. cout << "tidak bersentuhan" << endl;
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5280KB
stdin
0 0 5
0 10 5
stdout
bersentuhan