Prefix Sums Print
Programming Interview
Easy
4 views
Problem Description
Given {x}, Output prefix sum after each element (same order).
Input Format
First integer n. Second line n integers.
Output Format
n lines prefix sums.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p:
sys.exit(0)
it=iter(p)
try:
n=int(next(it))
except Exception:
n=0
out=[]
sm=0
for _ in range(n):
try:
sm+=int(next(it))
except Exception:
pass
out.append(str(sm))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!