Inverse Prefix Sum [AtCoder]

HyunMin Yang·2023년 1월 4일
1
post-thumbnail

Question


Method

1) Get the input of an integer N and a sequence S
2) We have to subtract every element of sequence S from each of the previous elements and put them in to variable A
3) Use a For loop in a range of 1 to N, sequence S's 0th place should change to sequence S's i-1th place
4) S[0] has changed into S[i-1], so now we can use 'append' to get the our sequence
5) Repeat this N times
6) Print the sequence A in the format provided


Code

N = int(input())
S = list(map(int,input().split()))
A = [S[0]]

for i in range(1,N):
    S[0] = S[i-1]
    A.append(S[i]-S[0])

for i in A:
    print(i, end=' ')

Results


profile
Hello World!

0개의 댓글