hdu 1003 java 开一维数组

View Code
import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int t, n, i;
int dp[] = new int[100000];
t = cin.nextInt();
int cases=0;
while (t > 0) {
t--;
int temp=1;
n = cin.nextInt();
int sum = 0;
int max=-9999999;
int pos=1, beg=1;
for (i = 1; i <= n; i++) {
dp[i]=cin.nextInt();
if(dp[i-1]>=0)
dp[i]+=dp[i-1];
else temp=i;
if(max<dp[i])
{max=dp[i];pos=i;beg=temp;}
}
cases++;
System.out.println("Case "+cases+":");
//System.out.println();
System.out.println(max+" "+beg+" "+pos);
if(t>0) System.out.println();
}
}
}

 

posted @ 2011-12-05 14:16  Because Of You  Views(447)  Comments(0Edit  收藏  举报