zoukankan      html  css  js  c++  java
  • Java 第十一届 蓝桥杯 省模拟赛 递增序列

    问题描述
      在数列 a[1], a[2], …, a[n] 中,如果 a[i] < a[i+1] < a[i+2] < … < a[j],则称 a[i] 至 a[j] 为一段递增序列,长度为 j-i+1。
      给定一个数列,请问数列中最长的递增序列有多长。
    输入格式
      输入的第一行包含一个整数 n。
      第二行包含 n 个整数 a[1], a[2], …, a[n],相邻的整数间用空格分隔,表示给定的数列。
    输出格式
      输出一行包含一个整数,表示答案。
    样例输入
    7
    5 2 4 1 3 7 2
    样例输出
    3

    package 蓝桥杯省模拟赛_高职组;
    
    import java.util.Scanner;
    
    public class 递增序列 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] num = new int[n];
            int temp=-1;
            int count=0;
            int max=0;
            for (int i=0;i<n;i++){
                num[i]=sc.nextInt();
                if(count==0){
                    temp=num[i];
                    count++;
                }
                if(temp<num[i]){
                    temp=num[i];
                    count++;
                }
                else{
                    temp=num[i];
                    max=Math.max(count,max);
                    count=1;
                }
    
            }
            System.out.println(max);
        }
    }
    
    
  • 相关阅读:
    mac 安装ROS2
    193 最长有效括号
    个人笔记
    个人笔记
    个人笔记-大佬主页
    笔记-吴恩达老师机器学习及深度学习
    个人笔记
    转载-资源链接
    枚举类型
    333333333333333333333333
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13074766.html
Copyright © 2011-2022 走看看