Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <ctime>
  5. #include <numeric>
  6. #include <iterator>
  7.  
  8. using namespace std;
  9.  
  10. class wypisanie {
  11. int help;
  12. public:
  13. wypisanie() : help(0) {};
  14. void operator()(const int x) {
  15. cout << ++help << " = " << x << endl;
  16. return;
  17. }
  18. };
  19.  
  20. class sumowanie {
  21. public:
  22. vector<int> operator()(vector<int> a , vector<int> b) {
  23. vector<int> zwrot;
  24. for ( vector<int>::iterator aa = a.begin() , bb = b.begin(); aa != a.end() && bb != b.end(); ++aa , ++bb ) {
  25. zwrot.push_back(( *aa ) + ( *bb ));
  26. }
  27.  
  28. return zwrot;
  29. }
  30. };
  31.  
  32. int main() {
  33. srand(time(NULL));
  34. vector<int> A(3) , B(3);
  35. vector<vector<int>> AB , BA;
  36.  
  37. for ( int i = 0; i < 10; ++i ) {
  38. for_each(A.begin() , A.end() , [] (int &a) {a = rand() % 10; });
  39. AB.push_back(A);
  40. for_each(B.begin() , B.end() , [] (int &a) {a = rand() % 10; });
  41. BA.push_back(B);
  42. }
  43.  
  44. //cout << "Pierwsza chmura: " << endl;
  45. //for_each(AB.begin(), AB.end(), [](vector<int> xx) {for_each(xx.begin(), xx.end(), wypisanie());});
  46.  
  47. //cout << "Druga chmura: " << endl;
  48. //for_each(BA.begin(), BA.end(), [](vector<int> xx) {for_each(xx.begin(), xx.end(), wypisanie());});
  49.  
  50. vector<int> centroidA(20) , centroidB(20);
  51. centroidA = accumulate(AB.begin() , AB.end() , centroidA , sumowanie());
  52. centroidB = accumulate(BA.begin() , BA.end() , centroidB , sumowanie());
  53.  
  54. cout << endl << endl;
  55. for_each(centroidA.begin() , centroidA.end() , wypisanie());
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement