Tax Note XML Conversion
Time limit1sMemory limit128 MB
Parse shorthand tax notes with rate, end month/year, and start month/day, then output valid entries as strict XML or mark ambiguous or invalid lines as bad data.
- Level
Medium6 of 10
- Topics
- String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Tax contracts in Kalii are recorded as short handwritten notes by officials. Each note contains a tax rate, the contract end month/year, and the new contract start month/day. The end day is always the 15th. The start year is determined relative to November 9, 2003: a start month/day on or after November 9 is in 2003, and an earlier month/day is in 2004.
Write a program that converts each shorthand note into XML. If a note is invalid or has more than one valid interpretation, treat that line as bad data.
Input
The input contains multiple data sets, one per line. A valid line contains the following three fields in this order. There may be zero or more spaces between adjacent fields.
-
Tax rate
- A whole-number rate is written as digits followed by
%. - A decimal point is not allowed.
- A fractional rate may be written with
/. The digit immediately before/is the numerator, and any digits before that are the whole-number part. The denominator must be2,4, or8, and the numerator must be smaller than the denominator. - The maximum tax rate is
99.875%.
- A whole-number rate is written as digits followed by
-
Contract end date
- The month has one or two digits, followed by a two-digit year.
- A single hyphen may separate the month and year.
- The end day is always the 15th.
-
Contract start date
- The month has one or two digits, followed by a two-digit day.
- A single hyphen may separate the month and day.
- Every month has 31 days.
Output
For each data set, indexes start at 1. For valid data, print the following XML. One indentation level is 4 spaces.
<Kalii Index=N>
<startdate>(start date)</startdate>
<rate>(tax rate)</rate>
<enddate>(end date)</enddate>
</Kalii>
(start date) has format DDMMMYY, and (end date) has format 15MMMYY. DD is a day from 01 to 31, MMM is one of JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, and YY is the last two digits of the year. Print the tax rate with exactly three digits after the decimal point.
If the data is invalid or ambiguous, print this single line.
<Kalii Index=N>BAD DATA</Kalii>