#K80962. Filter Fraudulent Orders
Filter Fraudulent Orders
Filter Fraudulent Orders
You are given a list of orders. Each order has an identifier and a spent amount. An order is considered fraudulent if its spending amount is identical to any of the spending amounts in the previous five accepted orders. In other words, maintain a sliding window of the most recent five accepted orders. If the current order's amount is already in this window, skip it; otherwise, accept the order and update the window (removing the oldest entry if needed).
Note: The numbers are given in order of arrival. Your task is to output the list of orders that are not fraudulent.
The formula for the sliding window check can be represented in LaTeX as follows:
$$\text{If } a_i \in \{a_{i-1}, a_{i-2}, \dots, a_{i-5}\} \text{ then order } i \text{ is fraudulent.}$$
inputFormat
The first line of input contains an integer n
representing the number of orders.
Each of the next n
lines contains two values separated by a space: the first is the order_id (an integer) and the second is the amount (a floating-point number).
outputFormat
For each valid (non-fraudulent) order, print a line containing the order_id and the amount separated by a space. The amount should be displayed with one decimal place.
## sample6
1 100.0
2 200.0
3 300.0
4 400.0
5 500.0
6 600.0
1 100.0
2 200.0
3 300.0
4 400.0
5 500.0
6 600.0
</p>