The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days. The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day. Now, you need to find out the span values for the given number of days and their daily prices. For example, if an array of 7 day's prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6} . FUNCTIONAL REQUIREMENTS: void stockSpan(int,int*);
Answers
Answer:
#include<iostream>
using namespace std;
int main()
{
int n,x=1,y=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
cout<<x;
for(int i=1;i<n;i++){
if(a[i]<a[i-1])
cout<<"\n"<<x;
else{
y+=2;
cout<<"\n"<<y;
}
}
}
Explanation:
Answer:
Stock span
Explanation:
The stock span problem exists as a financial problem where we maintain a series of n daily cost quotes for a stock and we must calculate the span of the stock’s price for all n days. The span Si of the stock’s price on a given day I exist represented as the highest number of consecutive days just before the assigned day, for which the cost of the stock on the current day exists smaller than or equal to its cost on the provided day. For illustration, if an array of 7 days prices exists shown as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}.
#SPJ3