3-7总结

今天针对与昨天的上课测试
import java.util.Scanner;


public class main {
    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);

        int[] list1 = new int[1000000];
        int n = cin.nextInt();
        for (int i = 0; i < 10; i++) {
            list1[i] = cin.nextInt();
        }
        int[] list2 = new int[1000000];
        int[] list3 = new int[1000000];
        list2[0] = list1[0];
        for (int i = 1; i < n; i++) {
            list2[i] = list2[i - 1] + list1[i];
        }
        int m = cin.nextInt();

        for (int i = 0; i < n - m; i++) {
            if (i == 0) list3[i] = list2[m - 1];
            list3[i] = list2[i + m - 1] - list2[i];
        }

        int max = list3[0];
        for (int i = 0; i < list3.length; i++) {
            if (list3[i] > max) max = list3[i];
        }

        System.out.println(max);
    }


}

 

代码做了具体的理解,代码如下!
posted @ 2023-03-07 20:57  xiaolllllin  阅读(8)  评论(0编辑  收藏  举报