#P6051. Sum of Integers in a String
Sum of Integers in a String
Sum of Integers in a String
You are given several lines of strings. Each line may contain several integers intermingled with other characters. Your task is to compute the sum of all integers in each line and print the result. If a line does not contain any integers, do not output anything for that line.
Note: Every two integers in a line are guaranteed to be separated by at least one non-digit character. In other words, between every two occurrences of an integer, there is a separator that matches the regular expression \D+
(in \(\LaTeX\): $$\\D+$$). Also, if the data contains a period .
, it should be treated as a separator. All integers in the input are simple non-negative integers without any extra sign.
inputFormat
The input consists of multiple lines. Each line is a non-empty string containing characters and digits. Read input until the end of file (EOF) or input stream.
outputFormat
For each line in the input that contains at least one integer, output a single line containing the sum of all integers found in that line. If a line does not contain any integers, do not output anything for that line.
sample
abc123xyz
123