import java.util.*;
/**
* HJ98 自动售货系统
*/
public class HJ098 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] prices = {2, 3, 4, 5, 8, 6};
int[] numbers = new int[6];
int[] coins = new int[4];
int balance = 0;
while (sc.hasNext()) {
String s = sc.nextLine();
String[] orders = s.split(";");
for (String order : orders) {
if (order.charAt(0) == 'r') {
// 初始化
String[] orderArgs = order.split(" ");
String[] numStr1 = orderArgs[1].split("-");
String[] numStr2 = orderArgs[2].split("-");
for (int i = 0; i < 6; i++) {
numbers[i] = Integer.parseInt(numStr1[i]);
}
for (int i = 0; i < 4; i++) {
coins[i] = Integer.parseInt(numStr2[i]);
}
balance = 0;
System.out.println("S001:Initialization is successful");
} else if (order.charAt(0) == 'p') {
// 投币
int money = Integer.parseInt(order.substring(2, order.length()));
if (money != 1 && money != 2 && money != 5 && money != 10) {
System.out.println("E002:Denomination error");
} else if ((money == 5 || money == 10) && (coins[0] + coins[1] * 2 < money)) {
System.out.println("E003:Change is not enough, pay fail");
} else if (getSum(numbers) == 0) {
System.out.println("E005:All the goods sold out");
} else {
if (money == 1) {
coins[0]++;
} else if (money == 2) {
coins[1]++;
} else if (money == 5) {
coins[2]++;
} else if (money == 10) {
coins[3]++;
}
balance += money;
System.out.println("S002:Pay success,balance=" + balance);
}
} else if (order.charAt(0) == 'b') {
// 购买商品
if (!containCommodit(order.substring(2))) {
System.out.println("E006:Goods does not exist");
} else if (numbers[Integer.parseInt(String.valueOf(order.charAt(3))) - 1] == 0) {
System.out.println("E007:The goods sold out");
} else if (balance < prices[Integer.parseInt(String.valueOf(order.charAt(3))) - 1]) {
System.out.println("E008:Lack of balance");
} else {
int commoditIndex = Integer.parseInt(String.valueOf(order.charAt(3))) - 1;
balance = balance - prices[commoditIndex];
numbers[commoditIndex]--;
System.out.println("S003:Buy success,balance=" + balance);
}
} else if (order.equals("c")) {
// 退款
if (balance == 0) {
System.out.println("E009:Work failure");
} else {
int[] reback = new int[4];
int back = coins[3] >= (balance / 10) ? balance / 10 : coins[3];
reback[3] = back;
coins[3] -= back;
balance -= (back * 10);
back = coins[2] >= (balance / 5) ? balance / 5 : coins[2];
reback[2] = back;
coins[2] -= back;
balance -= (back * 5);
back = coins[1] >= (balance / 2) ? balance / 2 : coins[1];
reback[1] = back;
coins[1] -= back;
balance -= (back * 2);
back = coins[0] >= (balance / 1) ? balance / 1 : coins[0];
reback[0] = back;
coins[0] -= back;
balance = 0;
System.out.println("1 yuan coin number=" + reback[0]);
System.out.println("2 yuan coin number=" + reback[1]);
System.out.println("5 yuan coin number=" + reback[2]);
System.out.println("10 yuan coin number=" + reback[3]);
}
} else if (order.charAt(0) == 'q') {
if (order.substring(2).equals("0")) {
for (int i = 0; i < 6; i++) {
System.out.println("A" + (i + 1) + " " + prices[i] + " " + numbers[i]);
}
} else if (order.substring(2).equals("1")) {
System.out.println("1 yuan coin number=" + coins[0]);
System.out.println("2 yuan coin number=" + coins[1]);
System.out.println("5 yuan coin number=" + coins[2]);
System.out.println("10 yuan coin number=" + coins[3]);
} else {
System.out.println("E010:Parameter error");
}
}
}
}
}
private static int getSum(int[] nums) {
int sum = 0;
for (int num : nums) {
sum += num;
}
return sum;
}
private static boolean containCommodit(String s) {
List<String> list = new ArrayList<>(6);
list.add("A1");
list.add("A2");
list.add("A3");
list.add("A4");
list.add("A5");
list.add("A6");
return list.contains(s);
}
}