Sum - Remove Last Occurring Zero
Coding Problem Keys
Sum - Remove Last Occurring Zero
Problem Statement
The program must accept N integers as the input. For each integer X among the N integers, the program must remove the last occurring 0 in X. Then the program must print the sum of those N modified integers as the output.
Boundary Condition(S)
1 <= N <= 100
1 <= Each Integer Value <= 10⁸
Input Format
The first line contains N.
The second line contains N integers separated by a space.
Output Format
The first line contains the sum of those N modified integers.
Example Input/Output 1
Input
4
160 875 5000 20111
Output
3501
Explanation
After removing the last occurring 0 in 160, the integer becomes 16.
The integer 875 has no zeros. So it remains same.
After removing the last occurring 0 in 5000, the integer becomes 500.
After removing the last occurring 0 in 20111, the integer becomes 2111.
So the sum of those modified values in 3502 (16 + 875 + 500 + 2111).
Hence the output is 3502.
Example Input/Output 2
Input
8
609 7070 21 308 800 2800 5007 690
Output
1771
Note: Max Execution Time Limit: 500 millisecs
Solution
Programming Language: Python 3 Language
n=int(input())
l=list(map(str,input().split()))
s=0
for i in l:
k="";f=0
for j in i[::-1]:
if(j=='0'):
f+=1
if(j!='0' or f!=1):
k+=j
s+=int(k[::-1])
print(s)
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments