Home > Back-end >  Who can teach me this a problem?
Who can teach me this a problem?

Time:10-07

5. The known value of each element in the input sequence at least two elements, design algorithm to find the elements in the sequence of all of the biggest rise, fall subsequence, for example, if the elements in the order (1,20,30,12,3,5,7,4,6,100,11,8), the output as (1), 30, 30,12,3 (), (3, 5, 7), (7, 4), (4,6,100),,11,8 (100),

CodePudding user response:

Give you a way of thinking, is very simple, you use an array to save all of the data, and then start from the first, if the next is ascending (is bigger than the current), so has been looking for is bigger than the current, if the next is small, then find the end of the output as a result, the search to the last time the final Numbers continue to next time, descending order is the same operation,

CodePudding user response:

reference 1st floor lirg8405 response:
give you a way of thinking, is very simple, you use an array to save all of the data, and then start from the first, if the next is ascending (is bigger than the current), so has been looking for is bigger than the current, if the next is small, then find the end of the output as a result, the search to the last time the final Numbers continue to next time, descending order is the same operation,

Ten bucks, who can help me to come?

CodePudding user response:

reference 1st floor lirg8405 response:
give you a way of thinking, is very simple, you use an array to save all of the data, and then start from the first, if the next is ascending (is bigger than the current), so has been looking for is bigger than the current, if the next is small, then find the end of the output as a result, the search to the last time the final Numbers continue to next time, descending order is the same operation,

Please

CodePudding user response:

For example
 int main (int arg c, const char * argv []) {
Int a []={1, 20, 30, 12, 3, 5, 7, 4, 6, 100, 11 and 8};
Int len=sizeof (a)/sizeof (int).
Int * p=(int *) malloc (sizeof (a));
Int I, j=0, k=0;
P=a [0] [j++];
For (I=1; iIf (a [I - 1] <=a [I] & amp; & ! K) {//keep ascending
P=a [j++] [I];
[I - 1]} else if (a & gt;=a [I] & amp; & K) {//keep descending
P=a [j++] [I];
} else {//ascending or descending order was damaged when
If (j> 0) {//if there are data output
Printf (" (");
For (int m=0; MPrintf (" % d ", p [m]);
}
Printf (" % d) ", p [1]).
}
J=0;
P=a [j++] [, I];
K=! k;//change the direction of ascending or descending order
}
}
If (j> 0) {//if there are data output
Printf (" (");
For (int m=0; MPrintf (" % d ", p [m]);
}
Printf (" % d) \ n ", p [1]).
}
Free (p);
return 0;
}

CodePudding user response:

reference 5 floor qybao reply:
give money to the money,,,

Bosses have qq?

CodePudding user response:

reference 5 floor qybao reply:
give money to the money,,,

Add my qq, 1606681676

CodePudding user response:

 
Int nArray []=,20,30,12,3,5,7,4,6,100,11,8 {1};
Int nCount=sizeof (nArray)/sizeof (int);
Int nOrder=0;
for(int i=0; i{
If (nOrder==0)
{
If (nArray [I + 1] & gt;=nArray [I])
{
NOrder=1;
}
The else
{
NOrder=2;
}

Printf (" % d % d ", nArray [I], nArray [I + 1));
}
Else if (nOrder==1)
{
If (nArray [I + 1] {
printf("\n");
NOrder=0;
- I;
continue;
}
Printf (" % d ", nArray [I + 1));
}
The else
{
If (nArray [I + 1] & gt;=nArray [I])
{
printf("\n");
NOrder=0;
- I;
continue;
}
Printf (" % d ", nArray [I + 1));
}
}
printf("\n");

CodePudding user response:

refer to the second floor weixin_46538077 response:
Quote: refer to 1st floor lirg8405 response:
give you a way of thinking, is very simple, you use an array to save all of the data, and then start from the first, if the next is ascending (is bigger than the current), so has been looking for is bigger than the current, if the next is small, then find the end of the output as a result, the search to the last time the final Numbers continue to next time, descending order is the same operation,

Ten bucks, who can help me to come?

Don't money, here is the code, understand their research,

CodePudding user response:

refer to 7th floor weixin_46538077 response:
Quote: refer to the fifth floor qybao reply:
give money to the money,,,

Add my qq 1606681676


QQ is not many years
  • Related