53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
# ver 1/ вариант решения 1
|
|
a = input().split()
|
|
len_a = len(a) - 1
|
|
for index, number in enumerate(a):
|
|
if len_a == 0:
|
|
print (number)
|
|
else:
|
|
if index == 0:
|
|
S = int(a[-1]) + int(a[1])
|
|
b = str(S)
|
|
elif index != 0 and index != int(len_a) :
|
|
n_index_0 = int(int(a.index(number)) + 1)
|
|
n_index_2 = int(int(a.index(number)) - 1)
|
|
n_0 = a[n_index_0]
|
|
N_2 = a[n_index_2]
|
|
S1 = int(n_0) + int(N_2)
|
|
b += " " + str(S1)
|
|
elif index == int(len_a):
|
|
S2 = int(a[0]) + int(a[-2])
|
|
b += " " + str(S2)
|
|
print (b)
|
|
|
|
|
|
# ver 2/ вариант решения 2 -короче
|
|
initial_list = input().split()
|
|
sum_list = []
|
|
left_index = -1
|
|
right_index = -len(initial_list) + 1
|
|
middle_index = 0
|
|
while middle_index < len(initial_list):
|
|
sum_list.append(initial_list[left_index] + initial_list[right_index])
|
|
left_index += 1
|
|
right_index += 1
|
|
middle_index += 1
|
|
print(sum_list)
|
|
|
|
# ver 3/ вариант решения 3
|
|
a = [int(item) for item in input().split()]
|
|
a2 = []
|
|
for i in range(len(a)):
|
|
if len(a) == 1:
|
|
print(a[0])
|
|
break
|
|
else:
|
|
if i == 0:
|
|
a2.append(a[-1] + a[i + 1])
|
|
elif i > 0 and i != len(a) - 1:
|
|
a2.append(a[i - 1] + a[i + 1])
|
|
else:
|
|
a2.append(a[i - 1] + a[0])
|
|
if a2 != 0:
|
|
for i in a2:
|
|
print(i, end=' ') |