Link
Bar Code Problem»
import java.util.Scanner;
class Barcode
{
public static void main (String [] args)
{
Scanner sc = new Scanner (System.in);
int x = sc.nextInt();
int [] inventory = new int[x];
int [] cost = new int [x];
for (int i = 0; i < x; i++)
{
inventory[i] = sc.nextInt();
cost[i] = sc.nextInt();
}
int total = 0;
int deliver = 0;
while (sc.hasNext())
{
int quantity = sc.nextInt();
int item = Integer.parseInt(Integer.toOctalString(Integer.valueOf(sc.next(), 2)));
int pos = member(inventory, item);
if (pos != -1) { total += quantity*cost[pos]; deliver += quantity; }
else { System.out.printf("item %d not in inventory\n", item); }
}
System.out.printf("deliver %d items from inventory, total cost = $%d\n", deliver, total);
}
public static int member (int [] a, int x)
{
for (int i = 0; i < a.length; i++)
{
if (a[i] == x){ return i; }
}
return -1;
}
}
-
mrmodd reblogged this from fuckyeahterminals
-
fuckyeahterminals posted this