Connection Status:
Competition Arena > SortMaterials
TCO07 Round 3 · 2007-03-07 · by Olexiy · Simple Math, String Parsing
Class Name: SortMaterials
Return Type: int
Method Name: totalVolume
Arg Types: (vector<string>, vector<string>)
Problem Statement

Problem Statement

Your shipping company has just delivered some materials to you, and you'd like to find out how many of these materials are useful. All materials are packed into cubical boxes. The information about each box will be given to you in a String[] data, with the i-th element representing the i-th box. Each element of data will be formatted as "EDGE QUALITY COLOR" (quotes for clarity), where EDGE and QUALITY are positive integers representing the length of an edge of the box and the quality of the material (higher is better), respectively. COLOR will be a sequence of lowercase letters representing the color of the material.

A String[] requirements will represent the specifications for your project. Each element of requirements will follow one of the following templates (all quotes for clarity only):

  • "EDGE=X" (where X is a positive integer), which means that you can use only materials from boxes with edge length equal to X.
  • "QUALITY=X" (where X is a positive integer), which means that you can use only materials with the quality greater than or equal to X.
  • "COLOR=s" (where s is a sequence of lowercase letters), which means that you can use only materials of color s.
Given all this information, you are to return the total volume of the materials you can use.

Notes

  • The volume of a box with edge length of X is equal to X*X*X.

Constraints

  • data will contain between 1 and 50 elements, inclusive.
  • Each element of data will contain between 5 and 50 characters, inclusive.
  • Each element of data will be formatted as "EDGE QUALITY COLOR" (quotes for clarity), where EDGE and QUALITY are integers between 1 and 99, inclusive, with no leading zeroes, and COLOR is a non-empty sequence of lowercase letters ('a'-'z').
  • requirements will contain between 0 and 50 elements, inclusive.
  • Each element of requirements will contain between 6 and 50 characters, inclusive.
  • Each element of requirements will be formatted as "EDGE=X" (where X is an integer between 1 and 99, inclusive, with no leading zeroes), "QUALITY=X" (where X is an integer between 1 and 99, inclusive, with no leading zeroes), or "COLOR=s" (where s is a non-empty sequence of lowercase letters ('a'-'z'). All quotes for clarity only.
Examples
0)
{"1 20 red", "2 30 blue", "10 1 green"}
{}
Returns: 1009

With no special requirements, you can use all the materials you get. The sum of the volumes is 1*1*1 + 2*2*2 + 10*10*10 = 1009.

1)
{"1 20 red", "2 30 blue", "10 1 green"}
{"QUALITY=20"}
Returns: 9

Now you must choose materials with QUALITY of at least 20, so you can not use the third box.

2)
{"1 20 red", "2 30 blue", "10 1 green"}
{"QUALITY=20", "QUALITY=25"}
Returns: 8
3)
{"1 20 red", "2 30 blue", "10 1 green", "5 5 red", "5 6 red"}
{"COLOR=red", "EDGE=5"}
Returns: 250
4)
{"1 20 red", "2 30 blue", "10 1 green", "5 5 red", "5 6 red"}
{"EDGE=1", "EDGE=5"}
Returns: 0

Obviously, no box can have an edge length of 1 and 5 simultaneously.

Submissions are judged against all 88 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SortMaterials with a public method int totalVolume(vector<string> data, vector<string> requirements) · 88 test cases · 2 s / 256 MB per case

Submitting as anonymous