A field expedition logs the weight of every artifact unearthed at a dig site, in the order each was found. Before shipping specimens back to the lab, the curator issues one culling directive that decides which artifacts are worth keeping. Each directive is one of five kinds:
GT k — keep artifacts whose weight is strictly greater than kLT k — keep artifacts whose weight is strictly less than kEQ k — keep artifacts whose weight is exactly kEVEN — keep artifacts whose weight is even (the accompanying parameter is ignored)ODD — keep artifacts whose weight is odd (the accompanying parameter is ignored)Given the directive and the logged weights, produce the list of weights that survive the cull, keeping them in their original discovery order.
Line 1: an integer n, the directive code (one of GT, LT, EQ, EVEN, ODD), and an integer k — all whitespace-separated. k is present even for EVEN/ODD but has no effect on the result.
Line 2 (present only if n > 0): n whitespace-separated integers, the logged artifact weights, in discovery order.
A single line with the surviving weights, space-separated, in their original order. If none survive (including when n = 0), print an empty line.
Example 1
Input
6 GT 10 3 15 10 22 5 12
Expected
15 22 12
Explanation
The directive keeps weights strictly greater than 10. Scanning in order: 3 (no), 15 (yes), 10 (no, not strictly greater), 22 (yes), 5 (no), 12 (yes). The survivors in order are 15 22 12.
Example 2
Input
5 EVEN 0 7 -4 9 10 3
Expected
-4 10
Explanation
The directive keeps even weights and ignores the parameter. Scanning in order: 7 (odd), -4 (even), 9 (odd), 10 (even), 3 (odd). The survivors in order are -4 10.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →