題目:
代碼:
import java.util.Scanner;
public class DivideCake {
public static void main(String[] args) {
int n;
int getW=0;
int weight;
int numF=0;
int cakeW;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
weight = scan.nextInt();
for(int i=1;i<=n;i++) {
cakeW = scan.nextInt();
getW +=cakeW;
if(getW>=weight) {
numF+=1;
getW=0;
}
}
if(getW!=0)
numF+=1;
System.out.println(numF);
}
}
主類名稱改為Main