作为一个家庭作业,我在java中有以下程序:
在一个书柜里,我们有一堆N本书,必须由K作家手工复制.每本书都有Ui页面,其中Ai是书.
我们需要从堆栈中为每个作者提供连续的书籍,我们不能分割书籍的页面.
制作一个程序,通过最小化作者将复制的最大页数,为作者提供书籍.
作为输入,用户将给出一串数字,其中第一个数字是书籍数量N,第二个数字是作者数量K,其余数字是每本书籍的页数.
作为输出,程序将向用户输出作者将复制的最大页数.
例:
输入:15 6 30 40 10 40 50 20 30 40 10 70 10 50 30 50 10
输出:90
在这个例子中,第一个作者可以拿book1 = 30和book2 = 40但是不能拿book1 = 30,book3 = 10.换句话说,你只从堆栈的顶部拿书而不混淆.
这是我的实现:
import java.util.*;
public class Library {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// to work with 1.6 erase the second "Integer"
//in 1.7 this works properly
List<Integer> booksList = new LinkedList<Integer>();
System.out.printf("Give: ");
String answer = input.nextLine();
String[] arr = …Run Code Online (Sandbox Code Playgroud)