Sum of subsequences P98835


Statement
 

pdf   zip

thehtml

Write a program that reads a sequence of subsequences of natural numbers, and prints the sum of each subsequence.

To solve this exercise, write a procedure

void read_and_add(int& sum, bool& end);

that reads a subsequence of natural numbers separated by |’+’| ended in comma or dot, returns the sum of the read integer numbers in the output parameter |sum|, and indicates if the read subsequence was the last sequence with the output parameter |end|. This case is detected because the las subsequence is the only one which end with a dot.

Input

Input consists of a non empty sequence of non empty subsequences of natural numbers. In each subsequence, the integer numbers are separated by |’+’|. All the subsequences end in comma, except the last one, that ends in a dot.

Output

Your program must print the sum of the elements of each subsequence in a different line.

Public test cases
  • Input

    1+2+3+4+5,1000+100+10+1,7,0+42+23.
    

    Output

    15
    1111
    7
    65
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C C++