b965: 第 2 題 矩陣轉換
http://zerojudge.tw/ShowProblem?problemid=b965
- while True:
- try:
- R,_,_=input().split()
- matrix=[]
- for _ in range(int(R)):
- matrix.append(input().split())
- operations=input().split()
- for operation in operations[::-1]:
- if operation==’1’:
- matrix=matrix[::-1]
- else:
- matrix=[ row[::-1] for row in matrix ]
- transpose=zip(*matrix)
- matrix=[]
- for row in transpose:
- matrix.append(row)
- print(len(matrix),len(matrix[0]))
- for row in matrix:
- string=’’
- for element in row:
- string+=element+’ ’
- print(string[:-1])
- except:
- break
- from sys import stdin
- data=stdin.readlines() # 用ctrl+d離開stdin回到python
- while(data):
- RCM=data.pop(0).strip(’\\r\\n’).split()
- b=[]
- for _ in range(int(RCM[0])):
- b.append(data.pop(0).strip(’\\r\\n’).split())
- m=data.pop(0).strip(’\\r\\n’).split()
- m.reverse()
- for i in m:
- if i==’0’:b=list(zip(*b))
- b.reverse()
- print(len(b),len(b[0]))
- for i in b:
- print(*i)