subject

Implement a simplified version of a crypto broker platform. Initially, there is an array of users, with each user depositing only cash - deposits[i] is the amount of cash the (i + 1)th user has deposited. Assume that for now the platform contains just a single stock and all operations are done with this stock only. All operations are supposed to be in the same currency, and currency exchange is not supported for now.
The platform should support the following 3 types of operations:
"deposit " - deposits money to the specified user account.
"buy " - the specified user buys the specified amount of crypto at the specified price. The platform should make sure the user has enough money in their account to process the operation.
"sell " - the specified user sells the specified amount of crypto at specified price. The platform should make sure the user has enough cryptos in their account to process the operation.
Your task is to return an integer array representing the total amount of money in the specified user's account after each operation.
Example
For deposits = [9, 7, 12] and
operations = [
"buy 1 3 2",
"sell 1 4 10",
"deposit 2 12",
"buy 2 10 2",
"buy 2 6 3"
]
the output should be cryptoTrading(deposits, operations) = [3, 3, 19, 19, 1].
Let's consider all operations:
The user with user_id = 1 wants to buy 3 shares of the stock at price = 2 - the required amount of money is needed_money = 3 * 2 = 6. The user has 9 ≥ 6 units of money in their account, so this operation will be processed successfully. After this operation, the user has 3 units of money remaining.
The user with user_id = 1 wants to sell 4 shares of the stock at price = 10 - this operation will not be processed successfully because the user does not have 4 shares of the stock. Since the operation is not processed successfully, the user still has 3 units of money remaining.
The user with user_id = 2 deposits 12 units of money into their account. After this operation, the user has 19 units of money.
The user with user_id = 2 wants to buy 10 shares the stock at price = 2 - the required amount of money is needed_money = 10 * 2 = 20. The user has 19 < 20 units of money in their account, so this operation will not be processed successfully. The user still has 19 units of money remaining.
The user with user_id = 2 wants to buy 6 shares of the stock at price = 3 - the required amount of money is needed_money = 6 * 3 = 18. The user has 19 ≥ 18units of money, so this operation will be processed successfully. After this operation, the user has 1 unit of money remaining.
So, the output is [3, 3, 19, 19, 1].
Input/Output
[execution time limit] 0.5 seconds (cpp)
[input] array. integer deposits
An array of integers representing the amount of money (in cash) that users deposit to their accounts.
Guaranteed constraints:
1 ≤ deposits. length ≤ 104,
1 ≤ deposits[i] ≤ 105.
[input] array. string operations
An array of strings representing the operations described above. Specifically, it's guaranteed that:
In buy and sell operations - amount and price are integers.
In all operations - user_id will be integers between 1 to deposits. length.
After each operation, the total amount of money in each user's account will be an integer.
Guaranteed constraints:
1 ≤ operations. length ≤ 104.
[output] array. integer
An array of integers where the ith element of the array represents the total amount of money in the specified user's account after the ith operation.
PLEASE DO THIS IS JAVA or C++
vector cryptoTrading(vector deposits, vector operations) {
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:00
Program description: a c# app is to be created to produce morse code. the morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). in sound-oriented systems, the dot represents a short sound and the dash represents a long sound. separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. in a sound-oriented system, a space is indicated by a short period of time during which no sound is transmitted. the international version of the morse code is stored in the data file morse.txt.
Answers: 3
question
Computers and Technology, 23.06.2019 07:30
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
What are the possible consequences of computer hacking? what is computer piracy? describe some examples. what are the effects of computer piracy? what are the possible consequences of computer piracy? what is intentional virus setting? describe some examples. what are the effects of intentional virus setting? what are the possible consequences of intentional virus setting? what is invasion of privacy? describe some examples. what are the effects of invasion of privacy? what are the possible consequences of invasion of privacy? what is an acceptable use policy and what is the purpose of the acceptable use policy what is intellectual property and how can you use it?
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
language consists of basic components, and they are called a. 3; mental images, concepts, and speech b. 2; language acquisition and linguistic relativity c. 3; heuristics, algorithms, and analogies d. 4; phonemes, morphemes, syntax, and semantics e. 2; words and grammar
Answers: 3
You know the right answer?
Implement a simplified version of a crypto broker platform. Initially, there is an array of users, w...
Questions
question
Health, 20.11.2020 18:40
question
Mathematics, 20.11.2020 18:40
question
Mathematics, 20.11.2020 18:40
question
Geography, 20.11.2020 18:40
Questions on the website: 13722367