4 solutions
-
-1
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); }}
Information
- ID
- 5625
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 1
- Tags
- # Submissions
- 510
- Accepted
- 200
- Uploaded By