325 - Identifying Legal Pascal Real Constants


Difficulty : easy

Solution Description :

Input parsing string problem

1. At first remove trialing and leading space.
   Example: ######1.2#####   Here, # denote the space(' ') character.
   After remove space then you got: 1.2

2. Check invalid character (i.e. all character must be in set {0123456789Ee+-.})
    Example: 1.2 is valid, 1.  2 is not valid. 1.a2 is not valid.

3. Check valid position for e or E. If position of the character is in begin or end then the position is invalid. It must also be preceded by a digit(0123456789), and be followed by a digit(0123456789) or + or -. And also check multiple e or E. If e or E more then 1 then is not valid.
   Example: 1.2e2 is valid, 1.e+1 is not valid, E2 is not valid, 2E is not valid, 1E1 is valid, 1E1E1 is not valid.

4. Check valid position for '.'. If position of the character is in begin or end then the position is invalid. It must also be preceded by a digit(0123456789), and be followed by a digit(0123456789). And also check multiple '.'. If '.' more then 1 then is not valid. And if position the character(.) after e or E then the position is not valid. 
   Example: 1.2.2 is not valid, .5 is not valid, 5. is not valid, 1e.5 is not valid, 1.2e5 is valid.

If all of these conditions are met, then the constant is legal. Otherwise, it's illegal.
Remember a blank line input is illegal.