Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <functional>
- #include <algorithm>
- #include <random>
- #include <numeric>
- using namespace std;
- double myfunction (double x, double y) {return x+ y*y;} // складывает квадраты элементов вектора
- double myfunction1 (double x, double y) {return x + abs (y);} // для оператора <
- bool comp (vector <double> a, vector <double> b) // сравнивает евклидову норму векторов
- {
- return accumulate(a.begin(), a.end(), 0, myfunction) < accumulate(b.begin(),b.end(), 0, myfunction);
- }
- bool operator< (vector <double> a, vector <double> b)
- {
- return accumulate(a.begin(), a.end(), 0, myfunction1) < accumulate(b.begin(),b.end(), 0, myfunction1);
- }
- int main() {
- vector <vector <double>> a (5, vector <double> (5));
- cout <<"vvedite diapazon"<<endl;
- int b;
- cin >>b;
- for (int i=0; i<5; i++)
- {
- for (int j=0; j<5; j++)
- {
- a[i][j] = rand () % (2*b +1) - b;
- }
- }
- for (int i=0; i<5; i++)
- {
- for (int j=0; j<5; j++)
- {
- cout << a[i][j]<< " ";
- }
- cout << endl;
- }
- /*double x = *min_element(a[0].begin(),a[0].end() );
- double y = *max_element (a[0].begin(),a[0].end());
- for (int i=1; i<5;i++)
- {
- if (x > *min_element(a[i].begin(),a[i].end()))
- x = *min_element(a[i].begin(),a[i].end());
- if (y < *max_element (a[i].begin(),a[i].end()))
- y = *max_element (a[i].begin(),a[i].end());
- }
- cout << y - x <<endl;*/
- /*for (int i=0; i<2; i++)
- {
- for (int j=0; j<5; j++)
- {
- cout << a[i][j]<< " ";
- }
- cout << endl;
- }
- if (a[0]<a[1])
- cout << "yes"<<endl;
- else cout << "no"<<endl;*/
- /*sort (a.begin(),a.end(),comp);
- for (int i=0; i<5; i++)
- {
- for (int j=0; j<5; j++)
- {
- cout << a[i][j]<< " ";
- }
- cout << endl;
- }*/
- vector <vector <double> > c = a;
- for (int i=0;i<5;i++)
- {
- auto x = sqrt (accumulate (a[i].begin(),a[i].end(),0,myfunction));
- cout << x << endl;
- transform (a[i].begin(),a[i].end(),c[i].begin(), [&x](double y){return y/x;} );
- }
- for (int i=0; i<5; i++)
- {
- for (int j=0; j<5; j++)
- {
- cout << c[i][j]<< " ";
- }
- cout << endl;
- }
- cout << accumulate(c[0].begin(), c[0].end(), 0.0, myfunction) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement