AmazonOA #324
Perform Queries
估计简单可在线判题
考点(AI 标注)模拟/实现迭代器设计
The queue starts empty. INSERT appends a package ID to the end of the queue. SHIP, if the queue holds at least 3 packages, ships the earliest 3 and returns them in that order; otherwise it returns the single-element list ["N/A"] and removes no package. Return the list of results of every SHIP; if there is no SHIP, return an empty list.
输入格式
The input is a compact JSON two-dimensional array whose items are ["INSERT",ID] or ["SHIP","-"]. On this site 1≤number of queries≤50000, and an ID has 0..16 Unicode characters, with spaces, empty names, duplicates and case differences allowed. Whitespace inside JSON strings must use JSON escapes, for example a space is written as \u0020, and non-ASCII characters use \uXXXX or surrogate pairs; the semantic strings are not shortened.
输出格式
Output a compact JSON two-dimensional array; whitespace and non-ASCII characters in strings use JSON escapes, with a space encoded as \u0020.
样例 1
输入:
[["INSERT","A"],["INSERT","B"],["SHIP","-"],["INSERT","C"],["SHIP","-"]]
输出:
[["N/A"],["A","B","C"]]
样例 2
输入:
[["INSERT","a\u0020\u0020b"],["INSERT",""],["INSERT","\ud83d\ude00"],["SHIP","-"]]
输出:
[["a\u0020\u0020b","","\ud83d\ude00"]]
样例 3
输入:
[["SHIP","-"],["INSERT","X"]]
输出:
[["N/A"]]
样例说明
The outputs are [["N/A"],["A","B","C"]]; the three packages unchanged, including an ID with a double space, an empty ID and an emoji; and [["N/A"]]. The N/ A in the original example is a display typo, and this site uses N/A throughout, as in the body.