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, 21.06.2019 20:50
Write a method in the heapintpriorityqueue class called merge that accepts another heapintpriorityqueue as a parameter and adds all elements from the other queue into the current queue, maintaining proper heap order such that the elements will still come out in ascending order when they are removed. your code should not modify the queue passed in as a parameter. (recall that objects of the same class can access each other's private fields.)
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
What are listed in the vertical columns across the top of the event editor? a. file names b. conditions c. check marks d. action types
Answers: 1
question
Computers and Technology, 23.06.2019 02:50
Define a class named movie. include private fields for the title,year, and name of the director. include three public functions withprototypes void movie: : settitle(cstring); , voidmovie: : setyear(int); , void movie: : setdirector(string); . includeanother function that displays all the information about a movie.write a main() function that declares a movie object namedmyfavoritemovie. set and display the object's fields.this is what i have but know its wrong since it will notcompile: #include#includeusing namespace std; //class declarationclass movie{private: string movietitle ; string movieyear; string directorname; public: void settitle(string title); void setyear(string year); void setdirector(string director); void displayinfo(); }; //class implementationvoid movie: : settitle(string title){ movietitle = title; cout< < "what is the title of themovie? "< > temp; myfavoritemovie.settitle(temp); cout< < "enter movie year"< > temp; myfavoritemovie.setyear(temp); cout< < "enter director'sname"< > temp; myfavoritemovie.setdirector(temp); //display all the data myfavoritemovie.displayinfo(); system("pause"); return 0; this code is not entirely mine someone on cramster edited my firstcode but then i try manipulating the new code and i still get acompile error message : \documents\visual studio 2008\projects\movie\movie\movie.cpp(46) : error c2679: binary '< < ' : no operator found which takes aright-hand operand of type 'std: : string' (or there is no acceptableconversion)c: \program files (x86)\microsoft visual studio9.0\vc\include\ostream(653): could be'std: : basic_ostream< _elem,_traits> & std: : operator< < > (std: : basic_ostream< _elem,_traits> & ,const char *)w
Answers: 1
question
Computers and Technology, 23.06.2019 06:20
What is a point-in-time measurement of system performance?
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
History, 16.04.2020 06:21
question
Mathematics, 16.04.2020 06:21
question
Mathematics, 16.04.2020 06:21
question
English, 16.04.2020 06:21
question
Mathematics, 16.04.2020 06:21
question
English, 16.04.2020 06:21
Questions on the website: 13722362