TopcoderArchiveVisit Topcoder
SRM20 Jun 2007
SRM 355

ValueAddedTax

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
ValueAddedTax
Method:
calculateFinalPrice
Parameters:
String, int, String[]
Returns:
double
Method signature:
double calculateFinalPrice(String product, int price, String[] food)
(be sure your method is public)

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.

Examples

  1. "milk"
    1
    {"bread", "butter", "milk"}
    Returns: 1.1
  2. "car"
    100
    {"bread", "butter", "milk"}
    Returns: 118.0
  3. "abc"
    57
    {"a", "b", "c"}
    Returns: 67.25999999999999
Back to all problems