现有延迟报道学生归队,归队学生编号延续该班现有编号依次往后,编写程序完成下列任务:输入学生身高,输出新的方阵布局图。例如:输入学生身高为168,新的方阵布局图如图3所示,学生在方阵的位置:3 , 4。
图3
f = open ( "stu.txt" , "r" )
a = [ ]
line=f.readline( ).split ( )
i = 1
while line != [ ] :
a . append ( [ line[ 0 ] , line [ 1 ] , i ] )
i += 1
line = f . readline ( ) . split ( )
n = len ( a ) - 1
a [ n ] [ 2 ] = -1
sg = input ( "请输入插入的学生身高 ( cm ) : " )
xh = str ( len ( a ) )
head = 1
p = head ; q = head
while : p = q
q = a [ q ] [ 2 ]
if q == head :
head = len ( a ) -1
else :
a . append ( [ xh , sg , a [ p ] [ 2 ] ] )
a [ p ] [ 2 ] = len ( a ) - 1
p = head m = 1
while p != -1 :
if m != 5 :
print ( a [ p ] [ 0 ] , end = " " )
m += 1
else :
print ( a [ p ] [ 0 ] )
m = 1