題目:
代碼:
import java.util.Scanner;
public class PlantApple2 {
public static void main(String[] args) {
int n;
int m;
int a;
int num=0;
int totalNum=0;
boolean isDrop=false;
int dropNum=0;
boolean[] dropTree;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
dropTree = new boolean[n+2];
for(int i=1;i<=n;i++) {
m = scan.nextInt();
for(int j=1;j<=m;j++) {
a = scan.nextInt();
if(a>0) {
if(num!=0)
if(num>a)
isDrop = true;
num = a;
}
else
num+=a;
}
totalNum+=num;
dropTree[i+1] = isDrop;
if(i == n-1)
dropTree[0] = isDrop;
if(i == n)
dropTree[1] = isDrop;
if(isDrop) {
dropNum++;
isDrop = false;
}
}
int dropCount = 0;
int continueNum =0;
for(int k=0;k<dropTree.length;k++) {
if(dropTree[k])
dropCount++;
else
dropCount = 0;
if(dropCount >= 3)
continueNum++;
}
System.out.print(totalNum+" ");
System.out.print(dropNum+" ");
System.out.print(continueNum+" ");
}
}
一定要把代碼中用于測(cè)試的內(nèi)容(如system.out)刪除脑漫,不然真的是白費(fèi)功夫!M恕碳却!
主類名稱改為Main