记录一下做的练习题
字符串原地旋转:五
三
mat = [[1,2,3],[3,4,5],[4,5,6]]
tag=0
total = 0
for i in mat:total = total + i[tag]tag +=1
print(total)
四
X = [[12,7,3],[4,5,6],[7,8,9]]
Y = [[5,8,1],[6,7,3],[4,5,9]]
res = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(X)):for j in range(len(X[i])):res[i][j] = X[i][j] + Y[i][j]
print(res)
五
s =['z','y','x','w','a','f','g','h','i']
s = s[::-1]
param = int(input("输入param: "))
front= s[:param]
behind= s[param:]front = front[::-1]
behind = behind[::-1]print(front + behind)
字符串原地旋转步骤:
1.逆序当前字符串
2.给定值为界,把逆序后的字符串分为两部分
3.将两部分各自再逆序
4.拼接逆序后的两部分字符串