Advertisement
damoncard

Something

Oct 22nd, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Shelf {
  3.     String []name;
  4.     int [] price, maxValue, item;
  5.     Scanner s = new Scanner (System.in);
  6.     public static void main(String[] args) {
  7.         // Prepare Store
  8.         int n = s.nextInt();
  9.         name = new String [n];
  10.         item = new int [n];
  11.         price = new int [n];
  12.         maxValue = new int [n];
  13.         while (n > 0) {
  14.             name[n] = s.next();
  15.             price[n] = s.nextInt();
  16.             maxValue[n] = s.nextInt();
  17.             n--;
  18.         }
  19.  
  20.         // Add Stock
  21.         while (true) {
  22.             String token = s.next();
  23.             if (token.equals("*")) {
  24.                 break;
  25.             } else {
  26.                 for (String v : name) {
  27.                     if (token.equals(v)) {
  28.                         item[name.indexOf(v)]++;
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.  
  34.         // Show stock
  35.         for (int j = 0 ; j <= 1 ; j++) {
  36.             int maxPrice = 0;
  37.             int items;
  38.             for (int i = 0 ; i < name.length ; i++) {
  39.                 if (j == 0) {
  40.                     items = item[i] - item[i]%maxValue[i];
  41.                 } else {
  42.                     items = item[i]%maxValue[i];
  43.                 }
  44.                 System.out.print(name[i] + " ");
  45.                 System.out.print(items + " ");
  46.                 maxPrice += items*price[i];
  47.             }
  48.             System.out.println(maxPrice);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement