You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>You are asked to design a simple order management system for a trading platform.</p>
17
+
<p>请设计一个简单的交易平台订单管理系统。</p>
18
18
19
-
<p>Each order is associated with an <code>orderId</code>, an <code>orderType</code> (<code>"buy"</code> or <code>"sell"</code>), and a <code>price</code>.</p>
<li><code>OrderManagementSystem()</code>: Initializes the order management system.</li>
27
-
<li><code>void addOrder(int orderId, string orderType, int price)</code>: Adds a new <strong>active</strong> order with the given attributes. It is <strong>guaranteed</strong> that <code>orderId</code> is unique.</li>
28
-
<li><code>void modifyOrder(int orderId, int newPrice)</code>: Modifies the <strong>price</strong> of an existing order. It is <strong>guaranteed</strong> that the order exists and is <em>active</em>.</li>
29
-
<li><code>void cancelOrder(int orderId)</code>: Cancels an existing order. It is <strong>guaranteed</strong> that the order exists and is <em>active</em>.</li>
30
-
<li><code>vector<int> getOrdersAtPrice(string orderType, int price)</code>: Returns the <code>orderId</code>s of all <strong>active</strong> orders that match the given <code>orderType</code> and <code>price</code>. If no such orders exist, return an empty list.</li>
OrderManagementSystem orderManagementSystem = new OrderManagementSystem();<br />
48
-
orderManagementSystem.addOrder(1, "buy", 1); // A buy order with ID 1 is added at price 1.<br />
49
-
orderManagementSystem.addOrder(2, "buy", 1); // A buy order with ID 2 is added at price 1.<br />
50
-
orderManagementSystem.addOrder(3, "sell", 2); // A sell order with ID 3 is added at price 2.<br />
51
-
orderManagementSystem.getOrdersAtPrice("buy", 1); // Both buy orders (IDs 1 and 2) are active at price 1, so the result is <code>[2, 1]</code>.<br />
52
-
orderManagementSystem.modifyOrder(1, 3); // Order 1 is updated: its price becomes 3.<br />
53
-
orderManagementSystem.modifyOrder(2, 1); // Order 2 is updated, but its price remains 1.<br />
54
-
orderManagementSystem.getOrdersAtPrice("buy", 1); // Only order 2 is still an active buy order at price 1, so the result is <code>[2]</code>.<br />
55
-
orderManagementSystem.cancelOrder(3); // The sell order with ID 3 is canceled and removed from active orders.<br />
56
-
orderManagementSystem.cancelOrder(2); // The buy order with ID 2 is canceled and removed from active orders.<br />
57
-
orderManagementSystem.getOrdersAtPrice("buy", 1); // There are no active buy orders left at price 1, so the result is <code>[]</code>.</div>
<li>The total number of calls to <code>addOrder</code>, <code>modifyOrder</code>, <code>cancelOrder</code>, and <code>getOrdersAtPrice</code> does not exceed <font face="monospace">2000</font>.</li>
68
-
<li>For <code>modifyOrder</code> and <code>cancelOrder</code>, the specified <code>orderId</code> is <strong>guaranteed</strong> to exist and be <em>active</em>.</li>
0 commit comments