fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef double db;
  5.  
  6. struct Point
  7. {
  8. double x, y;
  9. };
  10.  
  11. struct Quadrilateral
  12. {
  13. struct Point a, b, c, d;
  14. };
  15.  
  16. void Which_Quad(Quadrilateral q); // determine quad type
  17. db det_side(Point p, Point q); // determine side length
  18. db det_slope(db x1, db y1, db x2, db y2, db x3, db y3); // determine slope
  19.  
  20. int main()
  21. {
  22. Quadrilateral q;
  23. scanf("%lf%lf", &q.a.x, &q.a.y);
  24. scanf("%lf%lf", &q.b.x, &q.b.y);
  25. scanf("%lf%lf", &q.c.x, &q.c.y);
  26. scanf("%lf%lf", &q.d.x, &q.d.y);
  27.  
  28. Which_Quad(q);
  29.  
  30. return 0;
  31. }
  32.  
  33. void Which_Quad(Quadrilateral q)
  34. {
  35. db side1 = det_side(q.a, q.b);
  36. db side2 = det_side(q.b, q.c);
  37. // cout<<q.b.x<<" "<<q.b.y<<" "<<q.c.x<<" "<<q.c.y<<" "<<side2<<" "<<endl;
  38. db side3 = det_side(q.c, q.d);
  39. db side4 = det_side(q.d, q.a);
  40.  
  41. if (side1 == side2 and side2 == side3 and side3 == side4 and side4 == side1)
  42. {
  43. if (det_slope(q.a.x, q.a.y, q.b.x, q.b.y, q.d.x, q.d.y) == -1)
  44. {
  45. printf("Square\n");
  46. return;
  47. }
  48. else
  49. {
  50. printf("Rhombus\n");
  51. return;
  52. }
  53. }
  54. else if (side1 == side3 and side2 == side4)
  55. {
  56. if (det_slope(q.a.x, q.a.y, q.b.x, q.b.y, q.d.x, q.d.y) == -1)
  57. {
  58. printf("Rectangular\n");
  59. return;
  60. }
  61. else
  62. {
  63. printf("Parallelogram\n");
  64. return;
  65. }
  66. }
  67. else
  68. {
  69. printf("Other\n");
  70. return;
  71. }
  72. }
  73.  
  74. db det_side(Point p, Point q)
  75. {
  76. db side;
  77. side = sqrt(((p.x - q.x) * (p.x - q.x)) + ((p.y - q.y) * (p.y - q.y)));
  78. // cout<<side<<endl;
  79. return side;
  80. }
  81.  
  82. db det_slope(db x1, db y1, db x2, db y2, db x3, db y3)
  83. {
  84. if (((y2 - y1) == 0 and (x3 - x1) == 0) or ((x2 - x1) == 0 and (y3 - y1) == 0))
  85. {
  86. return -1;
  87. }
  88. else
  89. {
  90. db slope = (((y2 - y1) * (y3 - y2)) / ((x2 - x1) * (x3 - x2)));
  91. return slope;
  92. }
  93. }
Success #stdin #stdout 0.01s 5468KB
stdin
0 0
5 0
5 3
0 3
stdout
Rectangular