蓝桥杯 最长递增

蓝桥杯 最长递增_第1张图片

输入

7

5 2 4 1 3 7 2

输出

3

思路

这个思路也很简单,后面大于前面,长度加一。当后面不大于前面的时候,就是一个新的递增序列了,递增序列的长度最小为1。

代码

#include 
using namespace std;
int main()
{
  int max=0,templen,n;
  cin>>n;
  int a[n];
  for(int i=0;i>a[i];
  }
  templen=1;
   for(int i=1;ia[i-1]) templen++;
   else{
      if(templen>max){
        max=templen;
      }
      templen=1;
   }
  }
  cout<

你可能感兴趣的:(蓝桥杯,算法,职场和发展)