Advertisement
cyberjab

Untitled

Dec 7th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | Software | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <vector>
  7. #include <set>
  8. #include <ctime>
  9.  
  10. using namespace std;
  11.  
  12. void func(double a, double b, double h, vector <double>& aa, vector <double>& bb) {
  13.     for (double x = a; x <= b; x += h) {
  14.         double y = 3 * cos(5 * x) + 2 * sin(x);
  15.         if (y > 0) {
  16.             bb.push_back(y);
  17.         }
  18.         aa.push_back(x - y);
  19.         cout << x << "    " << y << endl;
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     const double PI = 3.141;
  26.     setlocale(LC_ALL, "RUS");
  27.     vector <double> aa;
  28.     vector <double> bb;
  29.     cout << "   X" << "          " << "Y" << endl;
  30.     func(-PI, PI, PI / 10, aa, bb);
  31.     int mn = min(aa.size(), bb.size());
  32.     vector < vector <double>> c;
  33.     cout << "Массив A: ";
  34.     for (auto now : aa) {
  35.         cout << now << " ";
  36.     }
  37.     cout << endl << "Массив B: ";
  38.     for (auto now : bb) {
  39.         cout << now << " ";
  40.     }
  41.     sort(bb.begin(), bb.end());
  42.     cout << endl << "Массив B после изменений: ";
  43.     for (auto now : bb) {
  44.         cout << now << " ";
  45.     }
  46.     int cnt = 0;
  47.     double midar = 0;
  48.     double minel = 10e9;
  49.     bool flag = false;
  50.     int cord_i = 0;
  51.     int cord_j = 0;
  52.     for (int i = 0; i < mn; i++) {
  53.         vector <double> cur = {};
  54.         for (int j = 0; j < mn; j++) {
  55.             double k;
  56.             if (aa[i] > bb[j]) {
  57.                 k = aa[i] - bb[j];
  58.             }
  59.             else if (aa[i] < bb[j]) {
  60.                 k = aa[i] + bb[j];
  61.             }
  62.             else {
  63.                 k = 0;
  64.             }
  65.             cur.push_back(k);
  66.             if (k > 0) {
  67.                 cnt++;
  68.                 midar += k;
  69.             }
  70.             if (k <= minel) {
  71.                 minel = k;
  72.                 if (i > j) {
  73.                     flag = true;
  74.                     cord_i = i;
  75.                     cord_j = j;
  76.                 }
  77.                 else {
  78.                     flag = false;
  79.                 }
  80.             }
  81.         }
  82.         c.push_back(cur);
  83.     }
  84.     cout << endl << "Матрица C:" << endl;
  85.     for (int i = 0; i < mn; i++) {
  86.         for (int j = 0; j < mn; j++) {
  87.             cout << setw(10) << c[i][j] << " ";
  88.         }
  89.         cout << endl;
  90.     }
  91.     if (flag) {
  92.         c[cord_i][cord_j] = -1;
  93.     }
  94.     cout << "Матрица C после изменений:" << endl;
  95.     for (int i = 0; i < mn; i++) {
  96.         for (int j = 0; j < mn; j++) {
  97.             cout << setw(10) << c[i][j] << " ";
  98.         }
  99.         cout << endl;
  100.     }
  101.     cout << "Среднее арифметическое положительных: " << midar / cnt << endl;
  102.     cout << "Минимальный элемент: " << minel << endl;
  103.     return 0;
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement