Проблем със задача Easter Gifts от Demo Fundamentals Mid Exam 22.06.2019
Здравейте, когато дам кода в Judge ми дава 70/100. Грешките са Runtime.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String[] gifts = s.nextLine().split("\\s+");
String command = s.nextLine();
while (!command.equals("No Money")) {
String[] tokens = command.split("\\s+");
switch (tokens[0]) {
case "OutOfStock":
for (int i = 0; i < gifts.length; i++) {
if (gifts[i].equals(tokens[1])) {
gifts[i] = "None";
}
}
break;
case "Required":
int index = Integer.parseInt(tokens[2]);
if (index < gifts.length) {
gifts[index] = tokens[1];
}
break;
case "JustInCase":
gifts[gifts.length-1] = tokens[1];
break;
}
command = s.nextLine();
}
for (String gift : gifts) {
if (!gift.equals("None")) {
System.out.print(gift + " ");
}
}
}
}