#C2739. Valid Number Checker

    ID: 46088 Type: Default 1000ms 256MiB

Valid Number Checker

Valid Number Checker

Given a string (s), determine whether it represents a valid number. In this context, a valid number can be either an integer or a floating-point number. The rules are as follows:

  • An integer consists of one or more digits, and may optionally start with a '+' or '-' sign. For example, 123, +123, and -123 are valid.
  • A floating-point number should contain exactly one decimal point, with at least one digit in total. It may also have an optional '+' or '-' sign at the beginning. For example, 123.45, +123.45, -123.45, .45 and 123. are valid.

The string (s) may include leading or trailing whitespace. Any other format (including scientific notation, multiple decimal points, or extraneous characters) is considered invalid. Formally, if we denote (D) as a digit (0-9), the valid number formats can be expressed in LaTeX as follows:

[ s \in {\text{[\textpm]? }(D+|, D* , . , D+ )} ]

Output (1) if (s) is valid, and (0) otherwise.

inputFormat

The input consists of a single line containing the string (s). Note that (s) may include leading or trailing whitespace.

outputFormat

Output a single integer: (1) if the input string is a valid number according to the rules described, or (0) otherwise.## sample

123
1