import sys
for s in sys.stdin:
s = list(map(int,s.split()))
Line=s[0] ; LineC=s[1] ; LineH=s[2] #矩陣初始化 #Line為長、LineC為寬
ALine = Line
A = []
AT = []
for j in range(Line):
imp = sys.stdin.readline()
imp = list(map(int,imp.split()))
for i in range(len(imp)):
A.append(imp[i])
#~~~~~~~~~~~~~~~~~~~~~~~~~#
Move = sys.stdin.readline() #操作代碼輸入
Move = list(map(int,Move.split()))
turn = 0
for i in range(LineH): #操作矩陣
if Move[i] == 0: #旋轉
for i in range(LineC):
for j in range(Line):
AT.append(A[(Line-1-j)*(LineC)+i])
if turn == 1:
Line,LineC = LineC,Line #旋轉後長寬互換
turn = 0
else:
Line,LineC = LineC,Line
turn = 1
A = AT
AT = []
#~~~~~~~~~~~~~~~~~~~~~~~~~#
else: #翻轉
if Line%2 != 0: #判定矩陣高是否為偶數
ALine = Line-1
ALine = int(ALine/2)
else:
ALine = int(Line/2)
for i in range(ALine):
for j in range(LineC):
A[j+(i*LineC)],A[(Line-1)*(LineC)-(i*LineC)+j] = A[(Line-1)*(LineC)-(i*LineC)+j],A[j+(i*LineC)]
#~~~~~~~~~~~~~~~~~~~~~~~~#
print(Line,end=' ') #最終輸出
print(LineC)
rmb = 0
for i in range(Line): #列印最終矩陣
for j in range(LineC):
jrmb = j+rmb
if j == LineC-1:
print(A[jrmb], end='')
else:
print(A[jrmb], end=' ')
rmb = jrmb+1
print('')
import sys
for s in sys.stdin:
s = list(map(int,s.split()))
Line=s[0] ; LineC=s[1] ; LineH=s[2] #矩陣初始化 #Line為長、LineC為寬
ALine = Line
A = []
AT = []
for j in range(Line):
imp = sys.stdin.readline()
imp = list(map(int,imp.split()))
for i in range(len(imp)):
A.append(imp[i])
#~~~~~~~~~~~~~~~~~~~~~~~~~#
Move = sys.stdin.readline() #操作代碼輸入
Move = list(map(int,Move.split()))
turn = 0
for i in range(LineH): #操作矩陣
if Move[i] == 0: #旋轉
for i in range(LineC):
for j in range(Line):
AT.append(A[(Line-1-j)*(LineC)+i])
if turn == 1:
Line,LineC = LineC,Line #旋轉後長寬互換
turn = 0
else:
Line,LineC = LineC,Line
turn = 1
A = AT
AT = []
#~~~~~~~~~~~~~~~~~~~~~~~~~#
else: #翻轉
if Line%2 != 0: #判定矩陣高是否為偶數
ALine = Line-1
ALine = int(ALine/2)
else:
ALine = int(Line/2)
for i in range(ALine):
for j in range(LineC):
A[j+(i*LineC)],A[(Line-1)*(LineC)-(i*LineC)+j] = A[(Line-1)*(LineC)-(i*LineC)+j],A[j+(i*LineC)]
#~~~~~~~~~~~~~~~~~~~~~~~~#
print(Line,end=' ') #最終輸出
print(LineC)
rmb = 0
for i in range(Line): #列印最終矩陣
for j in range(LineC):
jrmb = j+rmb
if j == LineC-1:
print(A[jrmb], end='')
else:
print(A[jrmb], end=' ')
rmb = jrmb+1
print('')
我也遇到同樣問題,求解(Python)
import sys
def rotate(l):
l = flip(l)
l2 = [[0 for i in range(R)] for j in range(C)]
print(l)
print(l2)
for i in range(R):
for j in range(C):
l2[j][i] = l[i][j]
return l2
def flip(l):
l.reverse()
return l
for line in sys.stdin:
l = []
R, C, M = map(int, line.split())
for i in range(R):
l.append(input().split())
Commands = input().split()
for command in Commands:
if command == "0":
l = rotate(l)
R, C = C, R
else:
l = flip(l)
print(R, C)
[print(" ".join(i)) for i in l]
import sys
for s in sys.stdin:
s = list(map(int,s.split()))
Line=s[0] ; LineC=s[1] ; LineH=s[2] #矩陣初始化 #Line為長、LineC為寬
ALine = Line
A = []
AT = []
for j in range(Line):
imp = sys.stdin.readline()
imp = list(map(int,imp.split()))
for i in range(len(imp)):
A.append(imp[i])
#~~~~~~~~~~~~~~~~~~~~~~~~~#
Move = sys.stdin.readline() #操作代碼輸入
Move = list(map(int,Move.split()))
turn = 0
for i in range(LineH): #操作矩陣
if Move[i] == 0: #旋轉
for i in range(LineC):
for j in range(Line):
AT.append(A[(Line-1-j)*(LineC)+i])
if turn == 1:
Line,LineC = LineC,Line #旋轉後長寬互換
turn = 0
else:
Line,LineC = LineC,Line
turn = 1
A = AT
AT = []
#~~~~~~~~~~~~~~~~~~~~~~~~~#
else: #翻轉
if Line%2 != 0: #判定矩陣高是否為偶數
ALine = Line-1
ALine = int(ALine/2)
else:
ALine = int(Line/2)
for i in range(ALine):
for j in range(LineC):
A[j+(i*LineC)],A[(Line-1)*(LineC)-(i*LineC)+j] = A[(Line-1)*(LineC)-(i*LineC)+j],A[j+(i*LineC)]
#~~~~~~~~~~~~~~~~~~~~~~~~#
print(Line,end=' ') #最終輸出
print(LineC)
rmb = 0
for i in range(Line): #列印最終矩陣
for j in range(LineC):
jrmb = j+rmb
if j == LineC-1:
print(A[jrmb], end='')
else:
print(A[jrmb], end=' ')
rmb = jrmb+1
print('')
我也遇到同樣問題,求解(Python)
import sys
def rotate(l):
l = flip(l)
l2 = [[0 for i in range(R)] for j in range(C)]
print(l)
print(l2)
for i in range(R):
for j in range(C):
l2[j][i] = l[i][j]
return l2
def flip(l):
l.reverse()
return l
for line in sys.stdin:
l = []
R, C, M = map(int, line.split())
for i in range(R):
l.append(input().split())
Commands = input().split()
for command in Commands:
if command == "0":
l = rotate(l)
R, C = C, R
else:
l = flip(l)
print(R, C)
[print(" ".join(i)) for i in l]
沒事,沒看清楚題目,過了