求一個3*3二維數組中每行的最大值和每行的和。
輸入格式:
在一行中輸入9個小於100的整數,其間各以一個空格間隔
輸出格式:
輸出3行3列的二維數組,並在每行后面分別輸出每行最大值和每行元素的和,每個數據輸出占4列。
輸入樣例:
3 6 5 9 8 2 1 4 5
輸出樣例:
3 6 5 6 14 9 8 2 9 19 1 4 5 5 10
1 # 二維數組中每行最大值和每行和 2 # Author: cnRick 3 # Time : 2020-3-31 4 matrix = list(map(int,input().split())) 5 cnt = 0 6 for i in range(3): 7 thisLine_max = -1 8 thisLine_sum = 0 9 for j in range(cnt,cnt+3): 10 print("{:4d}".format(matrix[j]),end="") 11 thisLine_sum += matrix[j] 12 if matrix[j] > thisLine_max: 13 thisLine_max = matrix[j] 14 print("{:4d}{:4d}".format(thisLine_max,thisLine_sum)) 15 cnt += 3