String to Integer (atoi)

MediumStrings
Next
StringParsingSimulation

Implement the conversion from a string to a 32-bit signed integer. 1. Skip leading spaces. 2. Read an optional + or - sign. 3. Read digits until a non-digit or the end. If there are no digits the value is 0. 4. If the value is outside the 32-bit range [-2147483648, 2147483647], clamp it to the nearest bound.

Input

A single line containing the string (it may start with spaces and contain letters and symbols).

Output

Print the resulting integer.

Constraints

0 <= length <= 200

Example 1
Input
42
Output
42

A plain number.

Example 2
Input
   -042
Output
-42

Leading spaces and zeros are skipped; the sign is applied.

Example 3
Input
4193 with words
Output
4193

Reading stops at the first non-digit.

Hints

String to Integer (atoi) - Medium Strings Problem | Skill Shiksha