package sss; import java.io.*; public class s1 { public static void main(String[] args) throws FileNotFoundException { // TODO 自动生成的方法存根 BufferedReader readTxt=new BufferedReader(new FileReader(new File("D:\0.txt"))); String textLine=""; String str=""; try { while(( textLine=readTxt.readLine())!=null) { str+=" "+ textLine; } } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } String[] numbersArray=str.split(" "); int length=numbersArray.length; int []cs=new int[length-1]; int i=0; for(i=0;i<length-1;i++) { cs[i]=Integer.parseInt( numbersArray[i+1]); } System.out.print("采集数组F[]: "); for(i=0;i<length;i++) { System.out.print(numbersArray[i]+" "); } System.out.print(numbersArray.length-1); System.out.println(); int []a=new int[cs.length]; int []b=new int[cs.length]; int []c=new int[cs.length]; int t=0,j=0,k=0; length=cs.length; for(i=0;i<length;i++) { if(cs[i]<0)continue; else {t=cs[i];break;} } for(;i<length-1;i++) { if(cs[i]*cs[i+1]>0) { t=t+cs[i+1]; if(cs[i]>0) {a[j]=t;} if(cs[i]<0) {b[k]=t;} } else { if(i==length-2) { if(cs[i]>0) {a[j]=t;b[k]=cs[i+1];} if(cs[i]<0) {b[k]=t;a[j]=cs[i+1];} } if(cs[i]>0) {a[j]=t;j+=1;t=cs[i+1];} else{b[k]=t;k+=1;t=cs[i+1];} } } //剪开数组始 int m = 0,n=0,p=0; for(i=0;i<a.length;i++) { if(a[i]==0) {m=i;break;} else continue; } for(i=m;i<a.length;i++) { a[i]=a[p]; p++; if(p==m-1)break; } p=0; for(i=0;i<a.length;i++) { if(b[i]==0) {n=i;break;} else continue; } for(i=n;i<b.length;i++) { b[i]=b[p]; p++; if(p==n-1)break; } //正数数组: System.out.print("正数数组a[]: "); for(i=0;i<length;i++) { System.out.print(a[i]+" "); if(i==length-1)System.out.println(a.length); } //负数数组: System.out.print("负数数组b[]: "); for(i=0;i<length;i++) { System.out.print(b[i]+" "); if(i==length-1)System.out.println(b.length); } //整合数组: System.out.print("整合数组D[]: "); for(i=0;i<length;i++) { System.out.print(a[i]+" "); System.out.print(b[i]+" "); if(i==length-1)System.out.println(a.length+b.length); } //剪开数组末 j=0; int sum; for(i=0;i<a.length;i++) { c[i]=a[i]; } for(i=0;i<a.length;i++) { sum=a[i]; for(j=i;j<a.length-1;j++) { sum=a[j+1]+b[j]+sum; if(sum>c[i])c[i]=sum; else continue; } } int max=c[0]; for(i=1;i<a.length;i++) { if(c[i]>max)max=c[i]; else continue; } System.out.println("最大值为:"+max); } }