#C10895. Warehouse Package Management
Warehouse Package Management
Warehouse Package Management
This problem simulates a warehouse package management system. The warehouse stores packages in various compartments where each compartment is identified by a unique code. Each package has an integer weight and a fragility indicator. You are required to process a series of operations to add packages to the warehouse and to query the sum of weights within a specified lexicographical range of compartment codes.
The operations are defined as follows:
- ADD code weight fragile: Adds a package with the given compartment code, weight, and fragility status. The fragile field is Y if the package is fragile and N otherwise.
- QUERY condition start_code end_code: Computes and outputs the sum of the weights of packages whose compartment codes fall in the interval \( [start\_code,\; end\_code] \) (inclusive). The condition can be one of the following:
- ALL: Consider all packages.
- FRAGILE: Consider only fragile packages (i.e. packages with fragile status Y).
- NONFRAGILE: Consider only non-fragile packages (i.e. packages with fragile status N).
Note that string comparisons are case-sensitive. For instance, compartment codes "A1" and "a1" are considered different.
Example:
Input: 5 ADD A1 100 Y ADD B2 200 N ADD C3 150 Y QUERY ALL A1 C3 QUERY FRAGILE A1 C3</p>Output: 450 250
inputFormat
The first line of the input contains an integer T representing the number of operations. Each of the following T lines contains an operation in one of the following formats:
-
ADD code weight fragile
• code: A unique compartment code (string). • weight: The weight of the package (an integer). • fragile: A string that is either "Y" (fragile) or "N" (non-fragile).
-
QUERY condition start_code end_code
• condition: One of "ALL", "FRAGILE", or "NONFRAGILE". • start_code, end_code: Strings representing the lexicographical range of compartment codes (inclusive).
All operations must be processed in the order they are provided.
outputFormat
For each QUERY operation, output an integer on a new line representing the sum of the weights of the packages that satisfy the query condition and whose compartment codes fall within the given lexicographical range.## sample
5
ADD A1 100 Y
ADD B2 200 N
ADD C3 150 Y
QUERY ALL A1 C3
QUERY FRAGILE A1 C3
450
250
</p>