Laboratory Report
Time limit2sMemory limit1024 MB
Given reference tables and patient results, print a fixed-width lab report that flags each result against its table's ranges.
- Level
Easy3 of 10
- Topics
- Implementation, String, Intervals
- Solved
- No attempts yet
Problem
You are assigned to write software for a medical laboratory. Part of the software generates reports on the medical tests that were conducted. A medical test is a series of measurements on specimens (such as blood or urine) taken from a patient. Each measurement has a name, a unit, and a result (value). For example, the Cholesterol in a blood sample might be 180 mg/dl. Each measurement also has a reference table. A reference table is a set of rules that assigns a status flag to a patient based on the measurement result. For example, if Triglycerides has a result in the range [10, 190], it is classified as normal. It is flagged as low or high when the result is below or above this range, respectively.
Given all the reference tables and the results for several patients, generate the medical test report for each patient.
Input
A text in the input is a non-empty string of arbitrary printable ASCII characters, including spaces, punctuation, letters, and digits, but no newline character. A text never starts or ends with a whitespace character. Every real number in the input is written in decimal format with at most 7 characters, and its absolute value does not exceed .
The input has several sections (at least 2 and at most 100). Each section ends with a line of exactly 80 = characters.
The first section describes the reference tables. There are at least 1 and at most 100 reference tables. Adjacent tables are separated by a line of exactly 75 - characters. The first line of a reference table is the measurement name, a text of at most 25 characters. Each name is unique among all reference tables. The second line is the measurement unit, a text of at most 15 characters. The rest of the table defines the flag rules. It is either a single line or a set of line pairs.
If the rules are a single line, that line gives the criterion for Normal. A result that does not meet the criterion is classified as Abnormal.
If the rules are a set of line pairs (at least 1 and at most 10 pairs), the first line of each pair is a classification criterion, and the second line is the flag name. The flag name is a text of at most 25 characters, preceded by two space characters.
In either case, a classification criterion is a text of at most 50 characters in one of the following forms, where A and B are real numbers and x is a measurement result:
Any number of spaces may appear between the parts of a criterion. For example, [2,5], [ 2 , 5], and 2 5 are valid and equivalent. When a table uses line pairs, the criteria partition the measurement value space correctly: every possible result matches exactly one of the criteria.
The later sections give the results for each patient. The first line of a section is the patient's name, a text of at most 60 characters. Each following line gives one result: the measurement name and the value (a real number), separated by between 1 and 20 spaces. Each patient has at least 1 and at most 100 results. A measurement name appears at most once per patient.
Output
For each section except the first, print the laboratory test report for that patient, followed by a line of exactly 80 = characters. A report consists of a line with the patient's name, followed by a table of the test results. The table format is shown in the sample output. If the section has k measurements, the table has exactly k + 4 lines, each exactly 75 characters long. Fill all empty positions with spaces.
The table has four columns. The Test column holds the measurement name and starts at character 1. The Result column holds the result value in the same format as the input and starts at character 27. The Unit column holds the measurement unit and starts at character 35. The Flag column holds the flag from classifying the result and starts at character 51. If the flag is Normal, write nothing in that cell except spaces.
The measurement rows appear in the same order as in the patient's input section. Besides the measurement rows, the table has a heading line and three separator lines of 75 - characters, as shown in the sample output.
Note: this problem is judged very strictly. Every character in your output, including spaces and letter case, must match the expected output exactly.