#P5238. Valid Integer Checker
Valid Integer Checker
Valid Integer Checker
This problem requires you to determine whether a given integer string x is valid under certain criteria.
An integer string x is valid if and only if:
- Format Validity: The string must either be
0
or, if it is not0
, it must consist of an optional negative sign '-' followed by a digit between 1 and 9, and then followed by any number (possibly zero) of digits between 0 and 9. No extra leading zeros are allowed. - Range Constraint: The integer value represented by the string x must lie within the interval \([l, r]\), i.e., \(l \le x \le r\).
You will be given the bounds \(l\) and \(r\) and then several test cases. For each test case, check if the given string x is a valid integer under the above conditions.
inputFormat
The input begins with a line containing two integers \(l\) and \(r\). The second line contains an integer \(T\), representing the number of test cases. Each of the following \(T\) lines contains a string representing the integer x to be checked.
outputFormat
For each test case, output a single line. Print LEGAL
if the string x is a well-formatted integer and its value is within the interval \([l, r]\); otherwise, print ILLEGAL
.
sample
0 100
5
0
50
-1
001
100
LEGAL
LEGAL
ILLEGAL
ILLEGAL
LEGAL
</p>