1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
qwelly [4]
3 years ago
8

Implement a simplified version of a crypto broker platform. Initially, there is an array of users, with each user depositing onl

y 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) {
}
Computers and Technology
1 answer:
Salsk061 [2.6K]3 years ago
3 0
Jriririiekeekekkksks
You might be interested in
What framework provides a simple API for performing web tasks?
Kryger [21]

Answer:

Prototype is a framework that provides a simple API for performing web tasks.

Explanation:

Prototype is a JavaScript framework that aims to ease up the development of dynamic web applications. It basically take out the complexity out of the client-side programming.

Following are some salient features of Prototype:

1) Applies useful methods to extend DOM elements and built-in types.

2) Provides advance support for Event Management.

3) Provides powerful Ajax feature.

4) Built-in support for class-style OOP.

5) Not a complete application development framework

5 0
3 years ago
Describe how you would create a Java program that prompted the user to correctly enter a username and password. The username is
schepotkina [342]

Answer:

Explanation:

The program in question would create a new Scanner Object which asks the user for the Username first. It would then save this input into a temporary variable and compare it to the actual username in the database. Since the username is not case sensitive, we would use the toLowerCase() method on both the input and the database username so that they match even if the letters are not the same case structure. If both usernames match then we would move on to ask the user for the Password and compare it with the database password for that user. Since this one is case sensitive we would compare as is. Finally, if both Username and Password match we would print "Hello World" otherwise we would print "Login Failed."

3 0
2 years ago
In which scenario would instant messaging be more useful than other forms of communication?
ivann1987 [24]
When you're busy doing things and/or be too sick for over the phone communication
7 0
3 years ago
When cleaning a computer, you need only worry about what you can see.
almond37 [142]

Answer:

False because the inside could be dirty and cause problems.

Explanation:

4 0
2 years ago
Which characteristic of Cloud computing allows data centers to better manage hard drive failures and allocate computing resource
MrMuchimi

Answer:

When working with cloud computing, drive failures and need for usage and data is easily identifiable, so in short term, all of the things that show the user/s what needs to be done is the characteristic.

Explanation:

5 0
2 years ago
Other questions:
  • Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
    13·1 answer
  • Your company sent several staff members for UML training. An outside vendor provided the training. Everyone who attended the tra
    5·1 answer
  • How might writing an online journal be different than writing in a paper one ​
    15·2 answers
  • Search the internet for news of a motor vehicle collision in your community involving drugs or alcohol. Keeping in mind that you
    8·1 answer
  • To enter a typed number into a cell, you press Tab or Backspace?​
    7·2 answers
  • Someone help ASAP! Match the type of information system with its description.
    13·2 answers
  • Want to.learn about computers​
    9·1 answer
  • What is ambiguous grammar, explain in maximum 50words.
    5·1 answer
  • An entrepreneur identifies and fills the gap between what the society needs and what is available is called​
    5·1 answer
  • PowerPoint is best described as:
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!