Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <ctime>
- #include <numeric>
- using namespace std;
- class wypisanie
- {
- int help;
- public:
- wypisanie() : help(0) {};
- void operator()(const double x)
- {
- cout << ++help << " = " << x << endl;
- return;
- }
- };
- class sumowanie
- {
- public:
- vector<double> operator()(vector<double> a, vector<double> b)
- {
- vector<double> zwrot;
- for (vector<double>::iterator aa = a.begin(), bb = b.begin(); aa != a.end(); ++aa, ++bb)
- {
- int cc = *aa + *bb;
- zwrot.push_back(cc);
- }
- return zwrot;
- }
- };
- int main()
- {
- srand(time(NULL));
- vector<double> A(3), B(3);
- vector<vector<double>> AB(10), BA(10);
- for (int i = 0; i < 10; ++i)
- {
- for_each(A.begin(), A.end(), [](double &a) {a = rand() % 10; });
- AB.push_back(A);
- for_each(B.begin(), B.end(), [](double &a) {a = rand() % 10; });
- BA.push_back(B);
- }
- //cout << "Pierwsza chmura: " << endl;
- //for_each(AB.begin(), AB.end(), [](vector<double> xx) {for_each(xx.begin(), xx.end(), wypisanie());});
- //cout << "Druga chmura: " << endl;
- //for_each(BA.begin(), BA.end(), [](vector<double> xx) {for_each(xx.begin(), xx.end(), wypisanie());});
- vector<double> centroidA(3), centroidB(3);
- centroidA = accumulate(AB.begin(), AB.end(), centroidA, sumowanie());
- centroidB = accumulate(BA.begin(), BA.end(), centroidB, sumowanie());
- cout << endl << endl;
- for_each(centroidA.begin(), centroidA.end(), wypisanie());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement