2 条题解

  • 0
    @ 2025-3-31 23:59:13

    import java.util.Scanner;

    public class Main2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    
        //定义记录的天数
        int day = sc.nextInt();
    
        //定义数组temperatureArr,记录每天的温度
        int[] temperatureArr = new int[day];
        for (int i = 0; i < day; i++) {
            temperatureArr[i] = sc.nextInt();
        }
    
        //定义在数组中,连续上涨温度的连续天数的最大值
        int max = 0;
        //定义在数组中,连续上涨温度的连续天数
        int count = 0;
    
        //遍历这几天的温度,并计算max和count
        for (int i = 1; i < temperatureArr.length; i++) {
            //用temp记录,方便比较相邻的温度
            int temp = temperatureArr[i - 1];
    
    
            if (temp < temperatureArr[i]) {
                count++;
                if (max < count) {
                    max = count;
                }
                //结束本次循环,并开始下一次循环
                continue;
            }
    
            //重置count大小,因为前面没有continue,所以前面不是连续上涨
            count = 0;
        }
    
        //输出结果
        System.out.println(max + 1);
    }
    

    }

    • 0
      @ 2024-11-10 9:58:19
      #include<bits/stdc++.h>
      using namespace std;
      int n,a[10000001],maxn=1,t,o=1;
      int main()
      {
      	cin>>n;
      	for(int i=1;i<=n;i++)cin>>a[i];
      	t=a[1];
      	for(int i=2;i<=n;i++){
      		if(a[i]>t){
      			t=a[i];o++;
      			if(o>=maxn)maxn=o;
      		}
      		else{
      			t=a[i];
      			o=1;
      		}
      	}
      	cout<<maxn;
          return 0;
      }
      
      • 1

      信息

      ID
      5625
      时间
      1000ms
      内存
      125MiB
      难度
      1
      标签
      递交数
      346
      已通过
      145
      上传者