defshift(N, M, A):""""""if(M % N)==0:return0defloc(count, oldIndex, curIndex, N, M, A):
newIndex =(oldIndex + M)% N
if count == N -1:return0if(newIndex == curIndex):
count = count +1
curIndex = curIndex +1return loc(count, curIndex, curIndex, N, M, A)else:
temp = A[newIndex]
A[newIndex]= A[curIndex]
A[curIndex]= temp
oldIndex = newIndex
count = count +1return loc(count, oldIndex, curIndex, N, M, A)
loc(0,0,0, N, M, A)
N, M =input().split(' ')
A =input().split(' ')
N =int(N)
M =int(M)
shift(N, M, A)# print(len(A))for i in A[:-1]:print(i, end=' ')print(A[N -1], end='')
方法2:
defreverse(start, end, A):"""
[start:end)
:return
"""
temp =None
end = end -1while start < end:
temp = A[start]
A[start]= A[end]
A[end]= temp
start = start +1
end = end -1defshift(N, M, A):"""
数组大小:param N:
位移:param M:
数组:param A:
数组:return:
"""if M ==0:return
reverse(0, N, A)
reverse(0, M, A)
reverse(M, N, A)return
N, M =input().split(' ')
A =input().split(' ')
N =int(N)
M =int(M)
M = M % N
shift(N, M, A)for i in A[:-1]:print(i, end=' ')print(A[N -1], end='')
题目 方法1def shift(N, M, A): """""" if (M % N) == 0: return 0 def loc(count, oldIndex, curIndex, N, M, A): newIndex = (oldIndex + M) % N if count == N - 1: return 0 if (newIndex == curIndex):