#C4965. Sum of Numbers in a String
Sum of Numbers in a String
Sum of Numbers in a String
In this problem, you are given a string that may contain integer numbers mixed with other characters. Your task is to calculate the sum of all the integers present in the string. A number is defined as a contiguous sequence of digits which may have an optional leading negative sign (i.e., a '-' in front).
For example, given the string "abc 123 def 456", the numbers extracted are 123 and 456, and their sum is 579. Your solution should correctly handle cases with no numbers, empty input, or multiple numbers in a string.
inputFormat
Input is provided on a single line from standard input (stdin). The line contains a string that may include letters, digits, spaces, and punctuation.
outputFormat
Output the sum of all the numbers found in the input string as a single integer on one line to standard output (stdout).## sample
abc 123 def 456
579