Parsing Real Numbers
InterviewTime limit1sMemory limit128 MB
Given T lines, decide whether each line is a valid real number with optional sign, decimal point, and exponent, allowing surrounding blanks.
- Level
Medium4 of 10
- Topics
- String, Implementation, Simulation, String matching
- Solved
- No attempts yet
Problem
Read one line of input and determine whether it represents a valid real number.
A real number may contain a decimal point, an exponent (introduced by the character e or E), or both, together with the usual decimal digits. The rules are:
- If a decimal point is present, there must be at least one digit on each side of the point.
- An optional sign (
+or-) may appear in front of the number and in front of the exponent, with no blank characters after the sign. - If an exponent is present, it is an integer and must not contain a decimal point.
- Blank characters may appear before or after the number, but never inside it.
There is no bound on the magnitude of the numbers, but for simplicity you may assume that each input line is at most 1000 characters long.
Input
The first line contains an integer , the number of test cases. Each of the next lines contains one input line to be checked.
Output
For each test case, print a single line containing LEGAL if the line is a valid real number, or ILLEGAL otherwise.