Given a string, determine if it is an int, a float or neither.
- 123 - int
- 62727.0033 - float
- 644c.33 - neither
Your code should output a different value depending on which it is. For example it could return "i" for int, "f" for float and "n" for neither.
The following are floats:
1.00 -0.0 1.0
The following are not floats:
1e3 1.0ec3 -1e3 1e-3 1e+3 --1.0 +1.0 NaN 1.0.0 1. .1 -001.1
The following are ints:
42 -2 -0
The following are not ints:
In short, the rule for floats is that it is a sequence of digits following by a
. followed by a sequence of digits. Optionally
- is prepended. If it starts with
0 then the
. must follow directly afterwards.
The rule for ints is that it is a sequence of digits where the first digit is not
0. The only exception is that
-0 are ints.
Either sort of number can have
- optionally prepended to it.
You can assume the input will only contain printable-ASCII.