Sum or subtract numbers from an input list X34211


Statement
 

pdf   zip

html

Given a list of n integers v0,…,vn−1, and a string s of length n and with characters ’+’ and ’-’, we need to print the result of summing or subtracting each vi depending on whether the i’th character of s is ’+’ or ’-’.

Input

The input begins with a positive natural number n on a first line. On a second line there are n integers v0,…,vn. Afterwards, there’s a sequence of lines, each with a string s of length n and characters ’+’ or ’-’.

Output

For each string s, the program has to print (∑i∈{0… n−1}∧ s[i]=′+′vi) − (∑i∈{0… n−1}∧ s[i]=′−′vi)

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++