问题 4482 --数组元素的插入

4482: 数组元素的插入★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 68  解决: 57
[提交][状态][命题人:]

题目描述

在一个数组的第x个位置插入一个新的数y

【Python】


n=int(input())
a=input().split()
x=int(input())
y=int(input())
b=[]
for i in range(n-1):
    node=[a[i],i+1]
    b.append(node)
node=____(1)______
b.append(node)

head=0
newnode=_____(2)_______
b.append(newnode)
if x==1:
    newnode[1]=head
    head=_____(3)_______
else:
    next=head
    s=1
    while next !=-1 and s<x-1:
         next=_____(4)________                                                                                                                                                          
         s+=1
    node=b[next]
    ______(5)_______
    node[1]=len(b)-1
    
next=head
while next!=-1:
    node=b[next]
    print(node[0],end=' ')
    next=node[1]


输入

有四行 第一行有一个整数n ( 5 <= n <= 100 ), 第二行有n个整数,第三行有一个整数x,为要插入的位置,第四行有一个整数y,为要插入的整数。

输出

更新后的数组。

样例输入
Copy
5
7 2 3 4 5
2
9
样例输出
Copy
7 9 2 3 4 5

提示

来源

SZS 

[提交][状态]