Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<time.h>
- using namespace std;
- void main()
- {
- setlocale(LC_ALL, "ukr");
- srand(time(NULL));
- const int n = 15;
- bool change = true;
- int arr[n], m = 0;
- for (int i = 0; i < n; i++)
- {
- arr[i] = rand() % 10 - 5;
- cout << arr[i] << " ";
- }
- cout << endl;
- int maxcount = 0;
- for (int i = 0; i < n; i++)
- {
- int count = 0;
- if (arr[i] < 0) {
- for (int j = i; j < n; j++)
- {
- if (arr[j] < 0) {
- count++;
- if (count > maxcount) { maxcount = count; }
- cout << count << " ";
- }
- }
- }
- }
- cout << endl << maxcount << endl;
- }
- for (int j = i; j < n; j++)
- {
- if (arr[j] < 0) {
- count++;
- if (count > maxcount) { maxcount = count; }
- }else{
- count = 0; //cбрасывать значение count кто будет?
- }
- }
- -3 -5 -4 3 4 -5 1 0 -3 -1 -1 -2 -5 -5 0
- 6
- #include <range/v3/all.hpp>
- int main()
- {
- int v[] { -2, 0, 2, -1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1, 2 };
- int m = ranges::max(v
- | ranges::view::group_by([](int a, int b){return (a < 0) && (b < 0);})
- | ranges::view::transform(ranges::distance)
- );
- assert(m == 4);
- }
- int main()
- {
- int a[12] {-1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1};
- unsigned current = 0, maxnegative = 0;
- for (int i = 0; i < 12; ++i) {
- if (a[i] < 0) {
- ++current;
- if (current > maxnegative) maxnegative = current;
- } else {
- current = 0;
- }
- }
- cout << maxnegative << endl;
- return 0;
- }
- #include <vector>
- #include <rxcpp/rx.hpp>
- int main()
- {
- std::vector<int> v{ -1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1, 1, 2, 1, 0 };
- auto m = rxcpp::observable<>::iterate(v)
- .scan(0, [](int a, int i) { return (i < 0) ? a + 1 : 0; })
- .scan(0, [](int a, int i) { return std::max<int>(a, i); })
- .distinct_until_changed();
- m | rxcpp::operators::subscribe<int>(rxcpp::util::println(std::cout));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement