ValueAddedTax
SRM 355 · 2007-06-20 · by Petr
Problem Statement
In Russia, the Value Added Tax is 18% for almost all goods, with the exception of certain food items, which have a Value Added Tax of only 10%.
You are given a String product, the name of a product, and an int price, the price of the product before tax. You are also given a String[] food, each element of which is the name of a food product. If the given product is an element in food, it is a food item (and thus subject to 10% tax), and otherwise, it is a non-food item (and thus subject to 18% tax). Return the price of the product after tax has been added.
Notes
- The returned value must have an absolute or relative error less than 1e-9.
Constraints
- product will contain between 1 and 50 characters, inclusive.
- Each character in product will be a lowercase letter ('a'-'z').
- price will be between 1 and 1000, inclusive.
- food will contain between 1 and 50 elements, inclusive.
- Each element of food will contain between 1 and 50 characters, inclusive.
- Each character in each element of food will be a lowercase letter ('a'-'z').
- All elements of food will be distinct.
"milk"
1
{"bread", "butter", "milk"}
Returns: 1.1
"car"
100
{"bread", "butter", "milk"}
Returns: 118.0
"abc"
57
{"a", "b", "c"}
Returns: 67.25999999999999
"ba"
654
{"ba"}
Returns: 719.4000000000001
"cafcab"
30
{"ed"}
Returns: 35.4
Submissions are judged against all 78 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ValueAddedTax with a public method double calculateFinalPrice(string product, int price, vector<string> food) · 78 test cases · 2 s / 256 MB per case