#K39602. Sum of Numeric Strings
Sum of Numeric Strings
Sum of Numeric Strings
You are given a list of strings. Each string may represent an integer in a valid format. A string is considered a valid integer if it consists only of an optional '+' or '-' sign followed by one or more digits. Your task is to compute the sum of the valid integer strings and ignore the strings that do not represent a valid integer. For example, the string 7.5
is not valid, but -5
is valid.
Input Format: The input is read from standard input. The first line contains an integer n — the number of strings. The following n lines each contain one string.
Output Format: Output a single integer representing the sum of all valid integer strings.
Note: You must use \( \LaTeX \) format for any formulas. For example, the condition for a valid integer can be written as:
\( \text{Valid if } s \text{ matches } [+-]?\d+ \)
inputFormat
The first line contains an integer ( n ) (( 0 \le n \le 10^5 )), representing the number of strings. Each of the following ( n ) lines contains a non-empty string.
outputFormat
Output a single integer result which is the sum of all valid integer strings from the input.## sample
4
123
456
abc
789
1368
</p>