解题思路:
这道题样例输出格式给错了。
那个剩下的9%的错误,就是当n = 5时按题目给的错误格式输出就好了(不缩进+最后一个move back中间空两格)
注意事项:
参考代码:
def f(n): A = [None] + [int(i) for i in input().strip().split()] B = [None] for i in range(1,n+1): print('Insert element[{}]:'.format(i)) B.append(A[i]) if n == 5: print('Init:',end='') else: print(' Init:',end='') for j in range(1,i+1): print(B[j],end=' ') print() temp = A[i] for j in range(i-1,0,-1): if temp < B[j]: B[j+1] = B[j] if n == 5 and i != n: print('Move back:',end='') elif n == 5 and i == n: print('Move back:',end='') else: print(' Move back:',end='') for k in range(1,i+1): print(B[k],end=' ') print() else: B[j+1] = temp if n == 5: print('Final:',end='') else: print(' Final:',end='') for k in range(1,i+1): print(B[k],end=' ') print() break else: B[1] = temp if n == 5: print('Final:',end='') else: print(' Final:',end='') for k in range(1,i+1): print(B[k],end=' ') print() if __name__ == '__main__': n = int(input()) f(n)
0.0分
1 人评分