Adjacent Sums
Python
Easy
2 views
Problem Description
Read n integers. Build a new list of size n-1 where b[i]=a[i]+a[i+1]. Output b (or EMPTY if n
Input Format
First line n. Second line n integers.
Output Format
One line b or EMPTY.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0])
a=list(map(int,p[1:1+n]))
if n<2:
sys.stdout.write('EMPTY')
else:
out=[]
for i in range(n-1):
out.append(str(a[i]+a[i+1]))
sys.stdout.write(' '.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!