StoneHaos

misha5

Dec 7th, 2020
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. class Triangle {
  8. protected:
  9.     int x1, y1;
  10.     int x2, y2;
  11.     int x3, y3;
  12.     double a, b, c;
  13. public:
  14.     Triangle() {
  15.         x1 = 0; y1 = 0;
  16.         x2 = 0; y2 = 1;
  17.         x3 = 1; y3 = 0;
  18.         a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  19.         b = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
  20.         c = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
  21.     }
  22.     Triangle(int x1, int y1, int x2, int y2, int x3, int y3) {
  23.         this->x1 = x1; this->y1 = y1;
  24.         this->x2 = x2; this->y2 = y2;
  25.         this->x3 = x3; this->y3 = y3;
  26.         a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  27.         b = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
  28.         c = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
  29.     }
  30.     bool is() {
  31.         return ((a + b > c) && (b + c > a) && (c + a > b));
  32.     }
  33.  
  34.     double P() {
  35.         return a + b + c;
  36.     }
  37.     double S() {
  38.         double p = (a + b + c) / 2.0;
  39.         return sqrt(p * (p - a) * (p - b) * (p - c));
  40.  
  41.     }
  42.     double geta() {
  43.         return a;
  44.     }
  45.     double getb() {
  46.         return b;
  47.     }
  48.     double getc() {
  49.         return c;
  50.     }
  51.  
  52.     void print() {
  53.         double ugol1 = acos((a * a + b * b - c * c) / (2 * a * b));
  54.         double ugol2 = acos((c * c + b * b - a * a) / (2 * c * b));
  55.         double ugol3 = acos((c * c + a * a - b * b) / (2 * c * a));
  56.         cout << "Triangle:\n"
  57.             << "\t" << "len1: " << a << "\n"
  58.             << "\t" << "len2: " << b << "\n"
  59.             << "\t" << "len3: " << c << "\n"
  60.             << "\t" << "ugol1: " << ugol1 << "\n"
  61.             << "\t" << "ugol2: " << ugol2 << "\n"
  62.             << "\t" << "ugol3: " << ugol3 << "\n"
  63.             << "\t" << "P: " << P() << "\n"
  64.             << "\t" << "S: " << S() << "\n";
  65.     }
  66.  
  67.     ~Triangle() {}
  68. };
  69.  
  70. class IsoTriangle : public Triangle {
  71. public:
  72.     IsoTriangle() {
  73.         x1 = 0; y1 = 0;
  74.         x2 = 0; y2 = 1;
  75.         x3 = 1; y3 = 0;
  76.         a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  77.         b = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
  78.         c = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
  79.     }
  80.     IsoTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
  81.         this->x1 = x1; this->y1 = y1;
  82.         this->x2 = x2; this->y2 = y2;
  83.         this->x3 = x3; this->y3 = y3;
  84.         a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
  85.         b = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
  86.         c = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
  87.     }
  88.  
  89.     bool is_iso() {
  90.         return (a == b || b == c || c == a);
  91.     }
  92.  
  93.  
  94.     ~IsoTriangle() {}
  95. };
  96.  
  97. int main(void) {
  98.     int n;
  99.     int m;
  100.     cin >> n >> m;
  101.     Triangle *arr = new Triangle[n];
  102.     int x1, y1;
  103.     int x2, y2;
  104.     int x3, y3;
  105.     for (int i = 0; i < n; ++ i) {
  106.         cout << "Triangle" << i << endl;
  107.         cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
  108.         arr[i] = Triangle(x1, y1, x2, y2, x3, y3);
  109.     }
  110.     IsoTriangle mx;
  111.     bool flag = false;
  112.     for (int i = 0; i < m; ++ i) {
  113.         cout << "IsoTriangle" << i << endl;
  114.         cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
  115.         IsoTriangle tmp = IsoTriangle(x1, y1, x2, y2, x3, y3);
  116.         if (!tmp.is_iso()) {
  117.             cout << "Error\n";
  118.             i --;
  119.         }
  120.         else {
  121.             if (!flag) {
  122.                 flag = true;
  123.                 mx = tmp;
  124.             }
  125.             else {
  126.                 if (tmp.S() > mx.S())
  127.                     mx = tmp;
  128.             }
  129.         }
  130.     }
  131.     for (int i = 0; i < n; ++ i) {
  132.         for (int j = 0; j < n; ++ j) {
  133.             if (i != j) {
  134.                 double d = arr[i].geta() / arr[j].geta();
  135.                 if (arr[i].getb() / arr[j].getb() == d && arr[i].getc() / arr[j].getc() == d) {
  136.                     cout << "Podob:\n";
  137.                     arr[i].print();
  138.                     arr[j].print();
  139.                     cout << endl;
  140.                 }
  141.             }
  142.         }
  143.     }
  144.     mx.print();
  145.     delete [] arr;
  146. }
Add Comment
Please, Sign In to add comment