← 返回 nvidia 的题目列表Python Data Processing Task (Parse, Aggregate, and Validate)
类型:online_judge
Problem: Python Data Processing Task (Parse + Aggregate + Validate)
In a chip testing/automation scenario, you are given test execution records. Each line represents one run:
<test_name>,<status>,<latency_ms>
Where:
test_name: a string without commas
status: PASS or FAIL
latency_ms: a non-negative integer
Write a Python program that reads records from stdin and:
Filters out all records with status == FAIL.
Groups remaining records by test_name and computes:
pass_count
avg_latency_ms (floor)
Outputs results sorted by:
pass_count descending
then avg_latency_ms ascending
then test_name lexicographically ascending
Input
stdin: multiple lines.
Output
Multiple lines, each:
<test_name> <pass_count> <avg_latency_ms>
Constraints
Number of lines N: 1 ≤ N ≤ 2e5
Lines may contain leading/trailing spaces (use strip())
Empty lines may appear and should be ignored
Tests
Input:
t1,PASS,10
t2,FAIL,3
t1,PASS,20
Output:
t1 2 15
Input:
a,PASS,5
b,PASS,5
Output:
a 1 5
b 1 5
Input:
x,FAIL,1
x,PASS,0
x,PASS,1
Output:
x 2 0
Input:
t1,PASS,1
t2,PASS,100
t2,PASS,2
Output:
t2 2 51
t1 1 1
Input:
z,PASS,0
a,PASS,0
z,PASS,0
Output:
z 2 0
a 1 0
Example
Input
t1,PASS,10
t2,FAIL,3
t1,PASS,20
Output
t1 2 15