← 返回 meta 的题目列表Parse System Metrics and Warn on Threshold Breaches
类型:online_judge
Problem: Parse System Metrics and Emit Threshold Warnings
Implement a script that reads multiple lines from standard input. Each line is split by whitespace into columns.
Given:
A column number n, 1-indexed;
A numeric threshold;
A required count x.
Scan every input line:
If the line does not have column n, skip it;
If column n is not numeric, skip it, e.g. header lines;
If the numeric value in column n is greater than threshold, increment a counter;
Once the counter reaches x, print a warning and terminate.
Command-line Arguments
The real script should support:
python monitor.py --column n --threshold threshold --count x < input.txt
Where:
--column: positive integer, the 1-based column index;
--threshold: numeric threshold;
--count: positive integer, the number of breaches needed to trigger a warning.
For online testing, the script may also support putting the configuration in the first input line:
n threshold x
The remaining lines are metric logs.
Output Format
If a warning is triggered, print:
WARNING: column {n} exceeded {threshold} at least {x} times
If no warning is triggered, print nothing.
Example
Input:
3 100 2
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
2 0 101 5630832
1 0 99 5630832
2 0 200 5630832
Output:
WARNING: column 3 exceeded 100 at least 2 times
Constraints
Up to 10^6 input lines;
Each line length up to 10^4;
Process the input as a stream; do not load the whole log into memory.
Example
Input
3 100 2
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
2 0 101 5630832
1 0 99 5630832
2 0 200 5630832
Output
WARNING: column 3 exceeded 100 at least 2 times