由买买提看人间百态

topics

全部话题 - 话题: stockprice
(共0页)

发帖数: 1
1
题目如下,可以直接google "hackrank stock maximize",测试自己代码是否正确:
https://www.hackerrank.com/challenges/stockmax
Your algorithms have become so good at predicting the market that you now
know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for
the next N days.
Each day, you can either buy one share of WOT, sell any number of shares of
WOT that you own, or not make any transaction at all. What is the maximum
profit you can obtain with an optimum trading strategy?
Input
The first line con... 阅读全帖
q**y
发帖数: 129
2
应该是leftMax[k+1] 和 stockPrice[k]相减吧。
我的accepted的c++ code (去除了IO).
long maxStockProfit (vector stockPrices) {
int maxSellPrice = 0;
long maxProfit = 0;

for (int dayIdx= stockPrices.size()-2; dayIdx>=0; dayIdx--) {
maxSellPrice = max(maxSellPrice, stockPrices[dayIdx+1]);
maxProfit += (maxSellPrice - stockPrices[dayIdx]) > 0? (maxSellPrice
- stockPrices[dayIdx]) : 0;
}
return maxProfit;
}
j*****u
发帖数: 1133
3
1. 我一开始想成根据history的stock price来做predict了,想了半天。。。
其实是这个题的变种
int array A里找两个position i和j,要求A[j]和A[i]的差maximum,同时i static void BestDay(int[] stockPrices, out int buyDate, out int sellDate)
{
buyDate = sellDate = 0;
int maxDiff = 0, minPrice = stockPrices[0], minPriceDate = 0;
for (int i = 1; i < stockPrices.Length; ++i)
{
int price = stockPrices[i];
int diff = price - minPrice;
if (diff > maxDiff)
{
buyDate = minPriceDate;
s... 阅读全帖
l******0
发帖数: 313
4
来自主题: JobHunting版 - C的fscanf的问题 (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: love1010 (学会move on), 信区: Programming
标 题: C的fscanf的问题
发信站: BBS 未名空间站 (Sat Aug 18 00:31:27 2012, 美东)
需要从一个文件里读数据写入一些变量里
文件是这样的格式 GOOG|588.88
需要将GOOG写入一个string里,然后将588.88写入一个float number里,我写了以下
code:
char tempprice[10];
char ticker[10];
fscanf(fr,"%[^|]|%[^\n]\n",ticker,tempprice);
float stockprice = stof(tempprice); //将string变成float
上面的code, ticker会正确得到GOOG,但是tempprice却无法得到588.88,请问哪里出
错了?
另外,有更优化的方法么
非常感谢
w********g
发帖数: 8
5
max = stockPrice[i];
是不是这句话有问题啊
d*****s
发帖数: 5610
6
来自主题: Stock版 - JCP等不到翻倍了
他在ron johnson前面买的,你自己看股价,2010-2012之间,股价没有低于20的,估计
他22进的。
“Former Apple executive Ron Johnson, who was handpicked by for the chief
executive role by Ackman, led the company to a 25 percent plunge in annual
revenue, a 50 percent decline in stockprice, and a 13 percent drop in
customer traffic. The makeover Johnson led failed, new shoppers did not come
, and the stock price fell from $42.44 in early 2012 to $12.68 on Tuesday,
handing Ackman a paper loss of more than $350 million. He amassed his 18
... 阅读全帖
l******0
发帖数: 313
7
来自主题: Programming版 - C的fscanf的问题
需要从一个文件里读数据写入一些变量里
文件是这样的格式 GOOG|588.88
需要将GOOG写入一个string里,然后将588.88写入一个float number里,我写了以下
code:
char tempprice[10];
char ticker[10];
fscanf(fr,"%[^|]|%[^\n]\n",ticker,tempprice);
float stockprice = stof(tempprice); //将string变成float
上面的code, ticker会正确得到GOOG,但是tempprice却无法得到588.88,请问哪里出
错了?
另外,有更优化的方法么
非常感谢
(共0页)