注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
1. adjust_quantities
You have the ingredient list of a one-person recipe. You want to cook it for many persons (defined by). So, you must multiply all the quantities.
The ingredient list consists of strings, each defining a specific product. They all have the following format:
- An integer (written with digits), defining the quantity.
- A space character.
- Some words, defining the product.
Modify the string by multiplying the initial integer by.
You do not have to take care of the singular/plural of the words defining the product. These words may contain some numbers, you must not modify them.
The order of the lines must be preserved.
Example
You want to cook a cake for 3 persons. Here is the initial ingredient list for one person:
2 eggs
200 grams of flour
150 grams of sugar
1 liter(s) of milk
You must output this list:
6 eggs
600 grams of flour
450 grams of sugar
3 liter(s) of milk
Implementation
Implement the function.
Parameters
- (int): Number of persons for which to prepare the recipe. Strictly positive integer.
- (List[str]): List of ingredients. All of them start with an integer, strictly positive.
Return value(List[str]): List of ingredients, with quantities multiplied by the number of persons.
Constraints
- Available RAM: 512MB
- Timeout: 6 seconds
2. filter_duplicates
Implement the function[ DISCUZ_CODE_6t]): Sequence of arrivals and departures of guests.Return value(int): The total gains of the day.
Constraints
- 1 <= length() <= 10
- 2 <= length() <= 26
- Available RAM: 512MB
- Timeout: 6 seconds
Example
Parameters (arrays are truncated in the screenshot):
100
(6) [45, 10, 25, 30, 15, …]
(8) [3, 3, 0, 4, 0, 2, 2, …]
Return value:
115
AI follow-up
In your loop, when a guest ID is found in, you remove that guest from the queue rather than moving them into. What situation in the input does this branch represent, and how does your code distinguish it from a guest's departure after being seated?
This question was generated by AI. It may contain errors. |