很简单,思路如下:
记录该学生的学号tmp和原始位置idx
先从列表中删除该学生,然后在idx+q位置插入该学生
n = int(input()) # 整数n,表示学生的数量,学生的学号由1到n编号
m = int(input()) # 整数m,表示调整的次数
students = []
# 初始化队列中学生的学号
for i in range(n):
students.append(i+1)
# m次调整,对students进行改变
for i in range(m):
stu = input().split()
p = int(stu[0]) # 学号为p
q = int(stu[1]) # 移动q
# 移动
tmp = p
idx = students.index(p)
students.remove(p)
students.insert(idx+q, tmp)
for stu in students:
print(stu, end=' ')