注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 匿名 于 2023-8-10 20:26 编辑
如果对你有帮助,真的求米!!!!不会消耗你的米,感谢感谢题目描述很多,3道全是实践题,最讨厌这种了
第一题:
Concert Ticket Exchange
编程挑战说明:
Concert tickets can be hard to come by, especially when going through the resale market. We would like to build our own concert ticket exchange system so that we can view available tickets in real-time. This system will listen to incoming ticket orders for a new concert venue, BT Arena. We'd like to build a system that listens to concert ticket orders and provides fans with this market information in the form of a price ladder.
Concert ticket orders arrive as a stream of events that can either add an order to our market data book or delete an order from our book. We also want to be able to delete all orders at given price level.
Add orders come with the following information:
Action - ADD
OrderId - unique identifier for order
Artist - concert performer, such as "TaylorSwift" or "Drake"
Price - price for the order
Quantity - positive quantity is a buy order and negative quantity is a sell order
Delete orders come with the following information:
Action - DEL
Artist - concert performer, such as "TaylorSwift" or "Drake"
OrderId - Unique identifier for the order to be deleted
Delete price levels come with the following information:
Action - DEL_PRICE
Artist - concert performer, such as "TaylorSwift" or "Drake"
Price - price level to be deleted
We'd like to keep track of these events so that fans can request a market view in the form of a price ladder. A price ladder is made up of n price levels for buy orders and sell orders. A price level consists of the Price, BuyQuantity, and SellQuantity. A price level will either have a non-zero BuyQuantity or SellQuantity, but not both. For buy orders, the best price is the highest price because that is the price a ticket holder would sell at. Conversely, the best price for sell orders is the lowest price. The streamed events will guarantee at least n price levels for both buys and sells.
输入:
Repeated number of order operations in the following format:
<ADD> <OrderId> <Artist> <Price> <Quantity>
<DEL> <OrderId> <Artist>
<DEL_PRICE> <Artist> <Price>
We can get orders for different artists in the same stream of operations. The last line of input will the artist and number of price levels that we would like to view in our ladder for both buy and sell orders.
<Artist> <NumberOfPriceLevels>
Example Input:
ADD 1 TaylorSwift 100 10
ADD 2 TaylorSwift 101 -10
ADD 3 TaylorSwift 99 5
ADD 4 TaylorSwift 102 -5
ADD 5 TaylorSwift 100 2
ADD 6 Drake 95 2
DEL 1 TaylorSwift
TaylorSwift 2
输出:
The price ladder should begin with the artist name and should be followed by a repeated list of levels.
<Artist>
<BuyQuantity> <Price> <SellQuantity>
The levels should be sorted by price in descending order and contain NumberOfPriceLevels for buy and sell orders. Levels with 0 BuyQuantity and 0 SellQuantity should not be printed.
Example Output:
TaylorSwift
0 102 5
0 101 10
2 100 0
5 99 0
测试 1
测试输入
下载测试 1 输入
ADD 1 TaylorSwift 100 10
ADD 2 TaylorSwift 101 -10
ADD 3 TaylorSwift 99 5
ADD 4 TaylorSwift 102 -5
ADD 5 TaylorSwift 100 2
DEL 1 TaylorSwift
TaylorSwift 2
预期输出
下载测试:1 项输出
TaylorSwift
0 102 5
0 101 10
2 100 0
5 99 0
测试 2
测试输入
下载测试 2 输入
ADD 1 TaylorSwift 100 10
ADD 2 TaylorSwift 101 -10
ADD 3 TaylorSwift 99 5
ADD 4 TaylorSwift 102 -5
ADD 5 TaylorSwift 98 2
ADD 6 TaylorSwift 99 5
DEL_PRICE TaylorSwift 100
TaylorSwift 1
预期输出
下载测试:2 项输出
TaylorSwift
0 101 10
10 99 0
完成下列的代码
import sys
import math
# Data classes
class AddOrder():
def __init__(self, orderId, artist, price, quantity):
self.orderId = int(orderId)
self.artist = str(artist)
self.price = float(price)
self.quantity = float(quantity)
class ModifyOrder():
def __init__(self, orderId, artist, price, quantity):
self.orderId = int(orderId)
self.artist = str(artist)
self.price = float(price)
self.quantity = float(quantity)
class DeleteOrder():
def __init__(self, orderId, artist):
self.orderId = int(orderId)
self.artist = str(artist)
class DeletePriceLevel():
def __init__(self, artist, price):
self.artist = str(artist)
self.price = int(price)
# TODO(candidate): implementation below
class PriceLadder():
def __init__(self):
pass
def AddOrder(self, order):
# TODO(candidate): implement
pass
def DeleteOrder(self, delete):
# TODO(candidate): implement
pale_symbol>, <execute_or_pass>, <bundle_or_individual_stocks>, <total_price>
apx E B 100.0
spj E I 130.0
sspx E I 20.0
dpx E B 900.0
spdx P /* no arbitrage opportunity */
测试 1
测试输入
下载测试 1 输入
3 5
apx 99.5 3 aapl 4 amzn 3 aarp 4
spj 200.0 2 spy 3 swg 2
sspx 65 2 spy 1 aapl 1
aapl 10.5
amzn 12.0
aarp 5.0
spy 45.0
swg 33.5
预期输出
下载测试:1 项输出
apx E I 98.00
spj E B 200.00
sspx E I 55.50
测试 2
测试输入
下载测试 2 输入
2 4
adgb 5404.0 3 tadb 2 goog 2 meta 1
tadb 2520.0 2 bbby 5 hmny 4
goog 125.0
meta 114.0
bbby 225.0
hmny 350.75
预期输出
下载测试:2 项输出
adgb P
tadb E B 2520.00
测试 3
测试输入
下载测试 3 输入
2 4
adgb 5402.0 3 tadb 2 goog 2 meta 1
tadb 2530.0 2 bbby 5 hmny 4
goog 125.0
meta 114.0
bbby 225.0
预期输出
下载测试:3 项输出
adgb P
tadb P
完成下列代码
import sys
class Bundle:
def __init__(self, name, price, components):
self.name = name
self.price = price
self.components = components
class Stock:
def __init__(self, name, price):
self.name = name
self.price = price
def PrintTrade(name, bundleOrStock, price):
p = "{:.2f}".format(price)
print("{} E {} {}".format(name, bundleOrStock, p))
def PrintNoTrade(name):
print("{} P".format(name))
class MarketWatchPortfolio:
def __init__(self, bundles, stocks):
self.bundles = bundles
self.stocks = stocks
def ExecuteTrades(self):
# TODO(candidate): fill out
pass
def ParseInputs():
bundles = list()
stocks = dict()
num_stocks = -1
num_bundles = -1
for line in sys.stdin:
parsed = line.strip().split(' ')
if num_bundles == -1 and num_stocks == -1:
num_bundles = int(parsed[0])
num_stocks = int(parsed[1])
continue
if num_bundles > 0:
components = list()
for i in range(3, len(parsed) - 1, 2):
components.append((int(parsed[i + 1]), parsed[i]))
bundles.append(Bundle(parsed[0], float(parsed[1]), components))
num_bundles -= 1
continue
s = Stock(parsed[0], float(parsed[1]))
stocks[parsed[0]] = s
return MarketWatchPortfolio(bundles, stocks)
def main():
portfolio = ParseInputs()
portfolio.ExecuteTrades()
if __name__ == '__main__':
main()
如果对你有帮助,真的求米!!!!不会消耗你的米,感谢感谢 |