C++ Program To Solve Record Beaker Problem

 What is Record Breaker Problem?

There is a club and somedays number of visitors in that club is more and somedays less. We have to calculate the Record Breaking Days. It will be record breaking day if that day has largest visitor than all the previous days and also larger than the next day.

Note: Very first day will be the record breaking day.

Program:

#include <iostream>
using namespace std;

int main()
{
    int n,count=0;

    cout << "Enter n: ";
    cin >> n;
    int a[n+1];

    cout << "Enter number of visitors every day: ";
    for(int i = 0; i < n; i++)  
        cin >> a[i];
    
    if(n==1)    //if there is only one day then it will be record breaking day
    {
        cout << "Number of record breaking days: " << 1;
        return 0;
    }
    
    //if no. of visitors in last day is largest
    //than all the previous days then it is record breaking day
    //but we have to check the next day also, so we put -1 there.
    a[n] = -1;
    int mx = -1;
    
    cout << "Record Breaking Days are: ";
    for(int i = 0; i <= n; i++)   //checking the record breaking day
    {
       if(mx < a[i] && a[i+1] < a[i])
        {
            mx = a[i];
            cout << a[i] << " ";
            count++;
        }
    }
    cout << endl << "Number of recording breaking days: " << count;
    return 0;
}

Output:

Enter n: 5
Enter number of visitors every day: 5 3 8 6 9
Record Breaking Days are: 5 8 9 
Number of recording breaking days: 3
To solve more problem click here.
C++ Program To Solve Record Beaker Problem C++ Program To Solve Record Beaker Problem Reviewed by Beast Coder on May 20, 2021 Rating: 5

No comments:

Powered by Blogger.