Sum or subtract numbers from an input list X34211


Statement
 

pdf   zip

Given a list of nn integers v0,,vn1v_0,\ldots,v_{n-1}, and a string ss of length nn and with characters ’+’ and ’-’, we need to print the result of summing or subtracting each viv_i depending on whether the ii’th character of ss is ’+’ or ’-’.

Input

The input begins with a positive natural number nn on a first line. On a second line there are nn integers v0,,vnv_0,\ldots,v_n. Afterwards, there’s a sequence of lines, each with a string ss of length nn and characters ’+’ or ’-’.

Output

For each string ss, the program has to print (i{0n1}s[i]=+vi)(i{0n1}s[i]=vi)(\sum_{i\in\{0\ldots n-1\}\wedge s[i]='+'}v_i)\;-\;(\sum_{i\in\{0\ldots n-1\}\wedge s[i]='-'}v_i)

Public test cases
  • Input

    8
    -15 16 -20 3 -13 -1 -14 12
    ++-+-++-
    ----+-++
    ---++++-
    --+++-+-
    ++++-+--
    +-+-+--+
    ---+++-+
    -+-+++-+
    -+-+--+-
    +-----++
    -+----+-
    ---++---
    +++-+---
    +--+++-+
    -+++++++
    +++-++-+
    -++--+-+
    ++---+-+
    -+-+-+++
    +---+-+-
    

    Output

    10
    2
    -18
    -56
    -2
    -40
    34
    66
    42
    -2
    36
    12
    -32
    4
    -2
    -10
    46
    56
    64
    -52
    
  • Information
    Author
    PRO1
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++