← 返回 instacart 的题目列表Calculate Inventory Total Cost
类型:online_judge
Problem: Calculate Inventory Total Cost
You are given a string[] items, where each element represents one inventory item in the following format:
sku|productName|quantity|unitPriceCents
Fields:
sku: product SKU.
productName: product name.
quantity: an integer quantity.
unitPriceCents: an integer unit price in cents.
Compute the total cost of all valid item records, in cents:
total = Σ(quantity × unitPriceCents)
If either quantity or unitPriceCents in a record is negative, ignore the entire record.
Input Format
Line 1: an integer n, the number of item records.
Next n lines: one pipe-delimited item record per line.
Output Format
Print one integer: the total cost of valid items, in cents.
Example 1
Input:
3
a100|apple|6|123
b200|cake|2|500
c300|milk|1|299
Output:
2037
Explanation: 6×123 + 2×500 + 1×299 = 2037.
Example 2
Input:
3
a100|apple|6|123
b200|cake|-2|500
c300|milk|1|-299
Output:
738
Explanation: The last two records contain negative numeric values and are ignored.
Example
Input
3
a100|apple|6|123
b200|cake|2|500
c300|milk|1|299
Output
2037