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