#C10096. String to Integer Conversion

    ID: 39263 Type: Default 1000ms 256MiB

String to Integer Conversion

String to Integer Conversion

You are given a string s which represents an integer in a possibly non-standard format. Your task is to implement a function that converts this string to a 32-bit signed integer (int). The function should discard any leading whitespace, handle an optional '+' or '-' sign, and parse the numerical digits until a non-digit character is encountered or the end of the string is reached.

If the numerical value is out of the 32-bit signed integer range, return the appropriate limit:

\( INT_{MAX} = 2^{31}-1 = 2147483647 \) and \( INT_{MIN} = -2^{31} = -2147483648 \).

If the string is empty or does not contain any valid conversion characters, return 0.

inputFormat

The input consists of a single line from standard input containing a string s that may include leading or trailing spaces and an optional sign.

Note: The string can include additional characters after the digits which should be ignored.

outputFormat

Output a single integer, which is the result of converting the string as per the rules described above. The output should be printed to the standard output.

## sample
42
42