78. Convert String to Integer

You are given a null-terminated string that may contain:

  • An optional sign (+ or -) at the beginning
  • numeric part made of digits
  • Other non-digit characters (e.g., letters, symbols) that should be ignored once they appear

Your task is to:

  • Convert the initial numeric part of the string to an integer
  • Stop parsing when a non-digit character is encountered
  • Return the result with the correct sign

Do not use atoi(), strtol(), or similar built-in functions.

 

Example-1

Input: "123abc"
Output: 123


Example-2

Input: "-45!"
Output: -45


Example-3

Input: "42@#"
Output: 42


Example-4

Input: "abc123"
Output: 0


Example-5

Input: "+78x90"
Output: 78


 

Loading...

Input

123abc

Expected Output

123