[Huawei OD machine test real questions] 100% pass rate of stock maximum return (C++) super detailed code comment code interpretation

[Huawei OD machine test real questions 2022&2023] real test catalog @click here @
[Huawei OD machine test real questions] signal transmission and reception & trial reading & @click here @
[Huawei OD machine real test questions] rent a car to ride the greenway & trial reading & @点here@

stock maximum gain

topic:

Assuming that the stock price is known for a certain continuous period of time, calculate the maximum profit that can be obtained by buying and selling.
Input a number price(p1,p2,p3,p4…pn) whose size is n, and pi is the stock price of the first day.
The format of pi is the stock price (non-negative integer) plus the currency unit Y or S, where Y stands for RMB and S stands for US dollar. It is stipulated that 1 US dollar can be exchanged for 7 RMB.
Pi Example 1: 123Y represents RMB 123.
Pi Example 2: 123S represents USD 123, which can be converted into RMB 861.
Assuming that you can buy or sell plastic tickets on any day, you can also choose to give up the transaction, please count it in the transaction The maximum income you can get in a period of n days (calculated in RMB

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/130674097