Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <set>
- #include <ctime>
- using namespace std;
- void func(double a, double b, double h, vector <double>& aa, vector <double>& bb) {
- for (double x = a; x <= b; x += h) {
- double y = 3 * cos(5 * x) + 2 * sin(x);
- if (y > 0) {
- bb.push_back(y);
- }
- aa.push_back(x - y);
- cout << x << " " << y << endl;
- }
- }
- int main()
- {
- const double PI = 3.141;
- setlocale(LC_ALL, "RUS");
- vector <double> aa;
- vector <double> bb;
- cout << " X" << " " << "Y" << endl;
- func(-PI, PI, PI / 10, aa, bb);
- int mn = min(aa.size(), bb.size());
- vector < vector <double>> c;
- cout << "Массив A: ";
- for (auto now : aa) {
- cout << now << " ";
- }
- cout << endl << "Массив B: ";
- for (auto now : bb) {
- cout << now << " ";
- }
- sort(bb.begin(), bb.end());
- cout << endl << "Массив B после изменений: ";
- for (auto now : bb) {
- cout << now << " ";
- }
- int cnt = 0;
- double midar = 0;
- double minel = 10e9;
- bool flag = false;
- int cord_i = 0;
- int cord_j = 0;
- for (int i = 0; i < mn; i++) {
- vector <double> cur = {};
- for (int j = 0; j < mn; j++) {
- double k;
- if (aa[i] > bb[j]) {
- k = aa[i] - bb[j];
- }
- else if (aa[i] < bb[j]) {
- k = aa[i] + bb[j];
- }
- else {
- k = 0;
- }
- cur.push_back(k);
- if (k > 0) {
- cnt++;
- midar += k;
- }
- if (k <= minel) {
- minel = k;
- if (i > j) {
- flag = true;
- cord_i = i;
- cord_j = j;
- }
- else {
- flag = false;
- }
- }
- }
- c.push_back(cur);
- }
- cout << endl << "Матрица C:" << endl;
- for (int i = 0; i < mn; i++) {
- for (int j = 0; j < mn; j++) {
- cout << setw(10) << c[i][j] << " ";
- }
- cout << endl;
- }
- if (flag) {
- c[cord_i][cord_j] = -1;
- }
- cout << "Матрица C после изменений:" << endl;
- for (int i = 0; i < mn; i++) {
- for (int j = 0; j < mn; j++) {
- cout << setw(10) << c[i][j] << " ";
- }
- cout << endl;
- }
- cout << "Среднее арифметическое положительных: " << midar / cnt << endl;
- cout << "Минимальный элемент: " << minel << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement