Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <vector>
  6. #include <string>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10. void fun(vector<int> &v);
  11. int main () {
  12. setlocale(LC_ALL, "Rus");
  13. int N, k;
  14. cout << "Введите количество элементов" << endl;
  15. cin >> N;
  16. vector <int> v(N);
  17.  
  18. cout << "Введите элементы" << endl;
  19. for (int i = 0; i < N; i++)
  20. {
  21. cin >> v[i];
  22. }
  23.  
  24. cout << "Значения второго вектора " << endl;
  25.  
  26. for (int i = 0; i < N; i++) {
  27. cout << v[i] << " ";
  28. }
  29. cout << endl<< "какому числу должно быть кратное? k= " << endl;
  30. cin >> k;
  31. double sum = 0;
  32. int kol = 0;
  33. for (int i = 0; i <N; i++)
  34. {
  35. if (v[i]%k == 0) {
  36. sum += v[i];
  37. kol += 1;
  38. }
  39. }
  40.  
  41. cout << sum / kol << endl;
  42.  
  43. auto max = *max_element(v.begin(), v.end());
  44. cout << "Максимум " << max << endl;
  45. void(*pfi)(int) = fun;
  46.  
  47.  
  48. auto kon = std::find(v.rbegin(), v.rend(), max);
  49. if (kon != v.rend()) {
  50. std::for_each(max, kon, pfi);
  51. }
  52.  
  53. _getch();
  54. return 0;
  55. }
  56.  
  57. void fun(vector<int> v) {
  58. int i;
  59. cout << v[i] * (-1);
  60. }
  61.  
  62. vector<int> fun(vector<int> v,vector<int>::iterator beg, vector<int>::iterator end) {
  63. while (beg != end)
  64. {
  65. v[beg] *= -1;
  66. beg++;
  67.  
  68. }
  69. return v;
  70.  
  71. }
  72.  
  73. #include <vector>
  74. #include <algorithm>
  75. #include <iostream>
  76.  
  77. struct Sum {
  78. Sum() { sum = 0; }
  79. void operator()(int n) { sum += n; }
  80.  
  81. int sum;
  82. };
  83.  
  84. int main()
  85. {
  86. std::vector<int> nums{3, 4, 2, 9, 15, 267};
  87.  
  88. std::cout << "до: ";
  89. for (auto n : nums) {
  90. std::cout << n << " ";
  91. }
  92. std::cout << 'n';
  93.  
  94. std::for_each(nums.begin(), nums.end(), [](int &n){ n++; });
  95. Sum s = std::for_each(nums.begin(), nums.end(), Sum());
  96.  
  97. std::cout << "после: ";
  98. for (auto n : nums) {
  99. std::cout << n << " ";
  100. }
  101. std::cout << 'n';
  102. std::cout << "сумма: " << s.sum << 'n';
  103. }
  104.  
  105. std::for_each(nums.begin(), nums.end(), [](int &n){ n++; });
  106.  
  107. void doit(vector<int>&v)
  108. {
  109. if (v.empty()) return;
  110. int b = 0, e = 0, m = v[0];
  111. for(int i = 0; i < v.size(); ++i)
  112. {
  113. if (v[i] > m) m = v[b = e = i];
  114. else if (v[i] == m) e = i;
  115. }
  116. for(int i = b+1; i < e; ++i)
  117. v[i] = -v[i];
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement