Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Shelf {
- String []name;
- int [] price, maxValue, item;
- Scanner s = new Scanner (System.in);
- public static void main(String[] args) {
- // Prepare Store
- int n = s.nextInt();
- name = new String [n];
- item = new int [n];
- price = new int [n];
- maxValue = new int [n];
- while (n > 0) {
- name[n] = s.next();
- price[n] = s.nextInt();
- maxValue[n] = s.nextInt();
- n--;
- }
- // Add Stock
- while (true) {
- String token = s.next();
- if (token.equals("*")) {
- break;
- } else {
- for (String v : name) {
- if (token.equals(v)) {
- item[name.indexOf(v)]++;
- }
- }
- }
- }
- // Show stock
- for (int j = 0 ; j <= 1 ; j++) {
- int maxPrice = 0;
- int items;
- for (int i = 0 ; i < name.length ; i++) {
- if (j == 0) {
- items = item[i] - item[i]%maxValue[i];
- } else {
- items = item[i]%maxValue[i];
- }
- System.out.print(name[i] + " ");
- System.out.print(items + " ");
- maxPrice += items*price[i];
- }
- System.out.println(maxPrice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement