← 返回 apple 的题目列表Validate and Aggregate HTTP Access Logs
类型:online_judge
Given a list of HTTP access-log strings, parse each log, determine whether it is valid, and compute request metrics.
For a precise executable specification, each log has the following format:
<ipv4> <timestamp> <url_or_api> <status_code>
The four fields are separated by exactly one space:
ipv4 must be an IPv4 address with exactly four decimal octets in [0, 255]. Leading zeros are not allowed except for 0 itself.
timestamp must be a valid UTC time in YYYY-MM-DDTHH:MM:SSZ format.
url_or_api must be non-empty, start with /, and contain no whitespace.
status_code must be a three-digit decimal HTTP status code in [100, 599].
A log is valid only if it has exactly four fields and every field passes validation. Invalid logs are excluded from all metrics.
For all valid logs, output:
total_requests: number of valid logs.
count_4xx: number of valid logs with status in [400, 499].
count_5xx: number of valid logs with status in [500, 599].
failure_percentage: (count_4xx + count_5xx) / total_requests * 100, or 0.00 when there are no valid logs. Print it with exactly two decimal places.
Input Format
First line: integer n.
Next n lines: one log string per line.
Output Format
total_requests count_4xx count_5xx failure_percentage
Constraints
1 <= n <= 100,000
Each log line has at most 1,000 characters.
Example
Input
5
192.168.1.1 2024-01-15T10:30:00Z /api/users 200
10.0.0.5 2024-01-15T10:31:00Z /api/orders 404
172.16.0.1 2024-01-15T10:32:00Z /api/payments 503
999.1.1.1 2024-01-15T10:33:00Z /api/test 200
127.0.0.1 invalid-time /health 500
Output
3 1 1 66.67