Problem Description
Ali was doing a physic experiment which requires him to observe an electric wave. He needs the height of each peak value and valley value for further study (a peak value means the value is strictly larger than its neighbors and a valley value means the value is strictly smaller than its neighbors). He did write these numbers down but he was too careless that he wrote them in a line without separations, such as “712495” may represent “7 12 4 9 5”. The only information he can remember was:
1. The data begins with a valley value
2. Each value is either a peak value or a valley value
Now he wants to insert blanks to make the data valid. If multiple solutions exist, he will choose the one with more blanks.
Input
The input consists several testcases.
The first line contains one integer N (1 <= N <= 100), the length of the data.
The second line contains one string S, the data he recorded.
S contains only digits.
Output
Print one integer, the maximum number of blanks he can insert.
Sample Input
6
712495
Sample Output
4
https://blog.csdn.net/kongming_acm/article/details/6919004
If all peak values or valley values are available, using MATLAB can solve your problem. For example, MATLAB reads all ASCII code numbers of what you have written and some functions such as sort() from MATLAB can obtain the minimum one of these code if blanks are kicked out. You can also find more functions from matlab to get what you want. Hope this is helpful to you. Thank you.