Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws IOException {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- String[] products = bf.readLine().split("\\s");
- long[] quantities = Arrays.stream(bf.readLine().split(" "))
- .mapToLong(Long::parseLong)
- .toArray();
- double[] prices = Arrays.stream(bf.readLine().split("\\s"))
- .mapToDouble(Double::parseDouble)
- .toArray();
- while (true) {
- String[] command = bf.readLine().split("\\s");
- String productName = command[0];
- if (productName.equals("done")) {
- break;
- }
- long productQuantity = Long.parseLong(command[1]);
- for (int a = 0; a < products.length; a++) {
- if (productName.equals(products[a])) {
- if (quantities.length > a && quantities[a] >= productQuantity) {
- System.out.printf("%s x %s costs %.2f%n", productName, productQuantity, productQuantity * prices[a]);
- quantities[a] -= productQuantity;
- break;
- } else {
- System.out.printf("We do not have enough %s%n", productName);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment