Home > Back-end >  Help to have a look at where is wrong?
Help to have a look at where is wrong?

Time:09-21

Problem description
Xiao Ming is using stock fluctuations to study stock, xiaoming got a stock closing price every day, he wanted to know, this stock for a few days what is the biggest fluctuation, that one day in these days, closing price and the absolute value of the difference between the closing price the day before what is the biggest,
Input format
Enter the first line contains an integer n, said xiao Ming to the closing price of the number of days in a row,
The second line contains n positive integers, in turn, said a day's closing price,
The output format
Output an integer, said the stock the maximum fluctuation of n days,
#include
using namespace std;
Const int N=1001;
Int main ()
{
Int x, I, n, j.
Int a [N]={0};
Int m [N]={0};
cin> n;
for(i=0; i{
cin> x;
A [I]=x;
}
for(j=0; Jfor(i=0; iM [j]=abs (a [I] - a/I + 1);
for(j=0; JIf (m [j] & gt; M [m + 1])
M=[m + 1] m [j];
The else m=[m + 1] m [j + 1);
Coutreturn 0;
}

CodePudding user response:

The second for loop inside the if - else statements with curly braces expansion

CodePudding user response:

Very repetitive
 # include 
using namespace std;
Const int N=1001;
Int main ()
{
Int x, I, n, j.
Int a [N]={0};
Int m [N]={0};
cin> n;
for(i=0; i{
cin> x;
A [I]=x;
}
for(j=0; Jfor(i=0; iM [j]=abs (a [I] - a/I + 1);//have the abs, and dual cycle?
for(j=0; JIf (m [j] & gt; M [m + 1])
M=[m + 1] m [j];
The else m=[m + 1] m [j + 1);
Coutreturn 0;
}


If only requires maximum, don't need to bother
 # include 
using namespace std;
Const int N=1001;
Int main ()
{
Int x, I, n, j.
Int a [N]={0};
int m=0;//Max
cin> n;
for(i=0; i{
cin> x;
A [I]=x;
}
for(j=0; JIf (abs (a [I] - [I + 1] a) & gt; M)
{
M=abs (a [I] - a/I + 1);
}
Coutreturn 0;
}


Try it, didn't run

CodePudding user response:

I know the
#include
using namespace std;
Const int N=1001;
Int main ()
{
Int x, I, n, j.
Int a [N]={0};
Int m [N]={0};
cin> n;
for(i=0; i{
cin> x;
A [I]=x;
}
for(j=0; Jfor(i=0; iM [j]=abs (a [I] - a/I + 1);//change the m [j] to m [I]
for(j=0; JIf (m [j] & gt; M [m + 1])
M=[m + 1] m [j];
The else m=[m + 1] m [j + 1);
Coutreturn 0;
}
  • Related