Increment/Decrement – Find Sum

The program must accept N string values representing N integers as the input. Each integer may or may not have an increment operator or a decrement operator. The program must increment or decrement the values of the integers by 1 based on the operator. Finally, the program must print the sum of N resulting integers as the output.

Boundary Condition(s):
1 <= N <= 100
-10^6 <= Each integer value <= 10^6

Input Format:
The first line contains N.
The second line contains N integers separated by a space.

Output Format:
The first line contains an integer representing the sum of the N resulting integer values.

Example Input/Output 1:
Input:
5
4++ 3 2– 10++ 15

Output:
35

Explanation:
4++ => 5
2– => 1
10++ => 11
The revised integer values are 5, 3, 1, 11 and 15.
The sum of the revised integer values is 35.

Example Input/Output 2:
Input:
4
-5++ -6– 5++ 7–

Output:
1

N=int(input())
S=input().split()
Req_Num=0
for i in S:
    if '++' in i:
        Req_Num+=int(i.split("++")[0])+1
    elif '--' in i:
        Req_Num+=int(i.split("--")[0])-1
    else:
        Req_Num+=int(i)
print(Req_Num)
Previous Article

Diamond Values

Next Article

Sort the Vowels

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *