Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
7.5 kB
2
Indexable
Never
[Problem Description]


You are required to develop a new second-hand market app.


The seller can register products to sell and the buyer can purchase products on the app.


To register, the seller attaches a tag to each product, which can be used for search on the app.


To buy, the buyer searches the tags of registered products and selects the cheapest one among the searched products.


The prices of products on the app change according to the tags attached to them. However, those of products registered after the price change, will not be affected.


 


Implement a second-hand market app with the features described above.


 


Implement each required function by referring to the following API description.


※ The function signature below is based on C/C++. As for Java, refer to the provided Solution.java and UserSolution.java.


The following is the description of API to be written in the User Code.


void init(int N)

This function is called in the beginning of each test case.

 

The number of tags available on the app is N.

 

There is no registered product on the app.

 

 

Parameters

  N : Number of tags available on the app (5 ≤ N ≤ 30 )

void addProduct(int mPrice, int tagNum, char tagName[][10])

The seller registers products to sell on the app.

 

The price of the registered product is mPrice.

The number of tags attached to the product is tagNum, each of which has a name tagName[].

 

tagName[] are all different from each other.

tagName[] is a string which consists of lowercase English letters of minimum 3, but no larger than 9, and ends with ‘\0.’

 

 

Parameters

  mPrice    : Price of the product registered on the app (1 ≤ mPrice ≤ 1,000,000 )

  tagNum   : Number of tags attached to the registered product on the app ( 3 ≤ tagNum ≤ 5 )

  tagName[] : Name of the tag attached to the registered product on the app ( 3 ≤ length of tagName[] ≤ 9 )

int buyProduct(char tag1[], char tag2[], char tag3[])

The buyer searches products which have all of the three tags on the app.

Among the searched products, the cheapest one is bought and the price value of the product is returned.

 

If there is no such product, -1 is returned.

 

Once the buyer purchases a product, it can no longer be seen on the app.

 

If two or more products are searched, it is guaranteed that there is only one cheapest product.

It is guaranteed that the number of products searched on the app is less or equal to 1,000.

 

The tags – tag1, tag2, tag3 – are all different from each other.

The tag is a string which consists of lowercase English letters of minimum 3, but no larger than 9, and ends with ‘\0.’

 

 

Parameters

tag1 : Name of the first tag ( 3 ≤ length of tag1 ≤ 9 )

tag2 : Name of the second tag ( 3 ≤ length of tag2 ≤ 9 )

  tag3 : Name of the third tag ( 3 ≤ length of tag3 ≤ 9 )

Returns

  Price of the product purchased by the buyer

void adjustPrice(char tag1[], int changePrice)

This function changes by changePrice the prices of all products with “tag1” among the ones on the app.

 

If changePrice is a positive number, the prices are increased; if it is a negative number, the prices are decreased.

 

If the price of the product is 100 and changePrice is 7, the price changes to 107.

If the price of the product is 100 and changePrice is -7, the price changes to 93.

 

There is no case where the changed price becomes 0 or a negative number.

 

If there is no product with “tag1”, nothing happens.

It is guaranteed that the number of products whose price is to be changed is less or equal to 3,000.

 

“tag1” is a string which consists of lowercase English letters of minimum 3, but no larger than 9, and ends with ‘\0.’

 

 

Parameters

tag1  : Name of the tag ( 3 ≤ length of “tag1” ≤ 9 )

  changePrice : Price value by which the price of the product with “tag1” changes ( -50,000 ≤ changePrice ≤ 50,000 )


 


 


[Example]


Let’s look into a case in [Table 1] where functions are called as below.


Order

Function

Return Value

1

init(5)

 

2

buyProduct(“white”, “black”, “red”)

-1

3

addProduct(50, 3, {“red”, “white”, “black”})

 

4

addProduct(35, 4, {“blue”, “red”, “green”, “white”})

 

5

addProduct(50, 3, {“black”, “red”, “green”})

 

6

addProduct(45, 5, {“red”, “black”, “white”, “green”, “blue”})

 

7

adjustPrice(“blue”, 7)

 

8

buyProduct(“white”, “black”, “red”)

50

9

addProduct(80, 3, {“green”, “white”, “black”})

 

10

buyProduct(“red”, “white”, “black”)

52

11

adjustPrice(“blue”, -4)

 

12

addProduct(33, 4, {“green”, “white”, “black”, “blue”})

 

13

buyProduct(“blue”, “red”, “white”)

38

14

buyProduct(“red”, “blue”, “white”)

-1

15

buyProduct(“green” , “white”, “black”)

33

[Table 1]

 


Order 7. After adjustPrice(“blue”, 7) is executed, the prices of the products and the tags are as shown in [Table 2].


Price

TAG

50

red, white, black

42

blue, red, green, white

50

black, red, green

52

red, black, white, green, blue

[Table 2]

 


Order 8. Two products are searched by buyProduct(“white”, “black”, “red”). However, since the price of the cheapest product is 50, the buyer purchases it.


The available products in the market are as shown in [Table 3].


Price

TAG

42

blue, red, green, white

50

black, red, green

52

red, black, white, green, blue

[Table 3]

 


Order 12. After addProduct(33, 4, {“green”, “white”, “black”, “blue”}) is executed, the prices of the products and the tags are as shown in [Table 4].


Price

TAG

38

blue, red, green, white

50

black, red, green

80

green, white, black

33

green, white, black, blue

[Table 4]

 


Order 13. Only one product is searched by buyProduct(“blue”, “red”, “white”) and the buyer purchases it.


Order 14. The buyer cannot purchase a product because no product is searched by buyProduct(“red”, “blue”, “white”). 


Order 15. Two products are searched by buyProduct(“green”, “white”, “black”). However, since the price of the cheapest is 33, the buyer purchases it.


 


 


 [Constraints]


1. init() is called in the beginning of each test case.


2. For each test case, a tag is a string which consists of lowercase English letters of minimum 3 but no larger than 9 and ends with ‘\0.’


3. For each test case, the number of tags is up to 30.


4. For each test case, addProduct() can be called up to 30,000 times.


5. For each test case, buyProduct() can be called up to 15,000 times.


6 For each test case, adjustPrice() can be called up to 5,000 times.


 


 


[Input and Output]


As the input and output are processed in the provided code in the Main, they are not processed separately in the User Code.


The output result for the sample input is in the format of “#TC number result.” It is the correct answer if the result is 100; it is the wrong answer if it is 0.
Leave a Comment