nyoj 经典的连续字串和

 1 import java.util.Scanner;
 2 
 3 
 4 public class 字串和 {
 5 
 6     public static void main(String[] args) {
 7         // TODO Auto-generated method stub
 8         Scanner scn=new Scanner(System.in);
 9         int len=scn.nextInt();
10         while(len-->0)
11         {
12             int len2=scn.nextInt();
13             int ans=scn.nextInt();
14             int max=ans;
15             for(int i=1;i<len2;i++)
16             {
17                 int n=scn.nextInt();
18                 if(max>0)
19                 {
20                     max+=n;
21                     
22                 }
23                 else
24                 {
25                     max=n;
26                 }
27                 ans=Math.max(ans, max);
28                 
29             }
30             
31             System.out.println(ans);
32             
33             
34         }
35 
36     }
37 
38 }
原文地址:https://www.cnblogs.com/hansongjiang/p/3916822.html