题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4561
WA 可能哪个特殊数据没有考虑,
大家帮我看看
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int T=input.nextInt();
int e=1;
while(T-->0){
int n=input.nextInt();
int a=0,f=0,max=0;
int sum=0;
for(int i=0;i<n;i++){
int b=input.nextInt();
if(b==2&&a!=0){
f++;
}
else if(b==2&&a==0){
sum++;
}
else if(b==-2&&++a==2){
sum+=2+f;
f=0;
a=0;
}else if(b==0){
sum=0;
a=0;
f=0;
}
if(max<f)
max=f;
if(max<sum)
max=sum;
}
System.out.println("Case #"+(e++)+": "+max);
}
}
}