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; //сбрасывать значение count кто будет?
- }
- }
- -3 -5 -4 3 4 -5 1 0 -3 -1 -1 -2 -5 -5 0
- 6
- 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;
- }
Add Comment
Please, Sign In to add comment