字节跳动 - 2048(AC 90%)
# l = [[0, 0, 0, 2], [0, 0, 0, 2], [0, 0, 4, 8], [0 ,0, 4, 8]] com = int(input()) l=[] for _ in range(4): l.append(list(map(int,input().split()))) if com == 1: for i in range(3, 0, -1): for j in range(4): if l[i-1][j] == l[i][j]: l[i][j] = 0 l[i-1][j] *= 2 for k in range(3, 0, -1): if l[k-1][j] == 0 and l[k][j] != 0: l[k-1][j] = l[k][j] l[k][j] = 0 if l[k-1][j] == l[k][j]: l[k-1][j] *= 2 l[k][j] = 0 elif com == 2: for i in range(0, 3, 1): print(i) for j in range(4): if l[i + 1][j] == l[i][j]: l[i][j] = 0 l[i + 1][j] *= 2 for k in range(0, 3, 1): if l[k + 1][j] == 0 and l[k][j] != 0: l[k + 1][j] = l[k][j] l[k][j] = 0 if l[k + 1][j] == l[k][j]: l[k + 1][j] *= 2 l[k][j] = 0 elif com == 3: for i in range(4): print(i) for j in range(3, 0, -1): if l[i][j - 1] == l[i][j]: l[i][j] = 0 l[i][j - 1] *= 2 for k in range(3, 0, -1): if l[i][k - 1] == 0 and l[i][k] != 0: l[i][k - 1] = l[i][k] l[i][k] = 0 if l[i][k - 1] == l[i][k]: l[i][k - 1] *= 2 l[i][k] = 0 elif com == 4: for i in range(4): print(i) for j in range(0, 3, 1): if l[i][j + 1] == l[i][j]: l[i][j] = 0 l[i][j + 1] *= 2 for k in range(0, 3, 1): if l[i][k + 1] == 0 and l[i][k] != 0: l[i][k + 1] = l[i][k] l[i][k] = 0 if l[i][k + 1] == l[i][k]: l[i][k + 1] *= 2 l[i][k] = 0 for i in range(4): print(" ".join(map(str, l[i])))
剩下的10%找不到样例了,有看出来的请告知呀!
#字节跳动##笔试题目#