Problem: Insert K number in an array between numbers with the same sign.
Compiling error:
Traceback (most recent call last):
File "./002596", line 12, in <module>
if (int(arr[i + h]) * int(arr[i + 1 + h]) >= 0):
ValueError: invalid literal for int() with base 10: '\r'
Code:
size = int(input())
s = input()
arr = s.split(' ') #I'm trying to solve Pascal problem, array shuld be got in 1 line
k = input()
for i in range(size):
arr[i] = int(arr[i])
h = 0
for i in range(size):
if (i + h + 1) < len(arr):
if (int(arr[i + h]) * int(arr[i + 1 + h]) >= 0):
arr.insert(i + 1 + h, k)
h+=1
for num in arr:
print(num, end=' ')
Comments
Post a Comment