Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <iostream>
- #include <string>
- using namespace std;
- void find() {
- int n, max = -10000, status = 0, m, left = 0, right = 0, big = 0, current = 1, equals = 1;
- cout << "Enter the size of array:";
- cin >> n;
- int A[n];
- for (int i = 0;i < n; i++) {
- cin >> A[i];
- if (i !=0 ) {
- if (A[i] >= A[i-1] && status == 1) {
- current += 1;
- if (A[i] == A[i - 1]) {
- equals += 1;
- } else {
- equals = 1;
- }
- }
- if (A[i] <= A[i-1] && status == -1) {
- current += 1;
- if (A[i] == A[i - 1]) {
- equals += 1;
- } else {
- equals = 1;
- }
- } else if (A[i] > A[i-1] && status == 0) {
- status = 1;
- current += 1;
- } else if (A[i] < A[i-1] && status == 0) {
- status = -1;
- current += 1;
- } else if (status == 0) {
- current += 1;
- } else {
- if (current > big) {
- big = current;
- left = i - current;
- }
- current = 1 + equals;
- status *= (-1);
- equals = 1;
- }
- cout << current << " " << equals<< " " << status << endl;
- }
- }
- if (current > big) {
- big = current;
- left = n - current;
- }
- //cout << i;
- for (m = left;m < left + big; m++) {
- cout << A[m] << " ";
- }
- }
- int main()
- {
- //1 0 0 3 3 2 1 0 -1
- find();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement