Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <stdio.h>
- #include <conio.h>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- void fun(vector<int> &v);
- int main () {
- setlocale(LC_ALL, "Rus");
- int N, k;
- cout << "Введите количество элементов" << endl;
- cin >> N;
- vector <int> v(N);
- cout << "Введите элементы" << endl;
- for (int i = 0; i < N; i++)
- {
- cin >> v[i];
- }
- cout << "Значения второго вектора " << endl;
- for (int i = 0; i < N; i++) {
- cout << v[i] << " ";
- }
- cout << endl<< "какому числу должно быть кратное? k= " << endl;
- cin >> k;
- double sum = 0;
- int kol = 0;
- for (int i = 0; i <N; i++)
- {
- if (v[i]%k == 0) {
- sum += v[i];
- kol += 1;
- }
- }
- cout << sum / kol << endl;
- auto max = *max_element(v.begin(), v.end());
- cout << "Максимум " << max << endl;
- void(*pfi)(int) = fun;
- auto kon = std::find(v.rbegin(), v.rend(), max);
- if (kon != v.rend()) {
- std::for_each(max, kon, pfi);
- }
- _getch();
- return 0;
- }
- void fun(vector<int> v) {
- int i;
- cout << v[i] * (-1);
- }
- vector<int> fun(vector<int> v,vector<int>::iterator beg, vector<int>::iterator end) {
- while (beg != end)
- {
- v[beg] *= -1;
- beg++;
- }
- return v;
- }
- #include <vector>
- #include <algorithm>
- #include <iostream>
- struct Sum {
- Sum() { sum = 0; }
- void operator()(int n) { sum += n; }
- int sum;
- };
- int main()
- {
- std::vector<int> nums{3, 4, 2, 9, 15, 267};
- std::cout << "до: ";
- for (auto n : nums) {
- std::cout << n << " ";
- }
- std::cout << 'n';
- std::for_each(nums.begin(), nums.end(), [](int &n){ n++; });
- Sum s = std::for_each(nums.begin(), nums.end(), Sum());
- std::cout << "после: ";
- for (auto n : nums) {
- std::cout << n << " ";
- }
- std::cout << 'n';
- std::cout << "сумма: " << s.sum << 'n';
- }
- std::for_each(nums.begin(), nums.end(), [](int &n){ n++; });
- void doit(vector<int>&v)
- {
- if (v.empty()) return;
- int b = 0, e = 0, m = v[0];
- for(int i = 0; i < v.size(); ++i)
- {
- if (v[i] > m) m = v[b = e = i];
- else if (v[i] == m) e = i;
- }
- for(int i = b+1; i < e; ++i)
- v[i] = -v[i];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement