#18410: 求解TT 您的答案為: 4 5 0 9 7 9 0 2 3 6 正確答案為: 7 3 3 1 3 1 0 6 5 0 NA 80%


bryan931218@gmail.com (游翔宇)

學校 : 國立宜蘭高級中學
編號 : 98903
來源 : [140.113.121.154]
最後登入時間 :
2024-09-03 19:11:45
b266. 矩陣翻轉 -- 2016 APCS 實作題第二題 | From: [140.111.76.235] | 發表日期 : 2019-07-11 11:58

有點不懂後面數字是怎麼跑出來的,輸入不是只有一組嗎? 為什麼最後輸出的答案跟正確答案完全不一樣?

因為是直接把輸入的數字加到列表裡操作,所以照理來說就算答案錯了應該也只會是順序出問題,結果輸出的答案跟正確答案裡面的數字完全不同,這不是很奇怪嗎>.<

求第五次測資謝謝

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('')

 
#20020: Re:求解TT 您的答案為: 4 5 0 9 7 9 0 2 3 6 正確答案為: 7 3 3 1 3 1 0 6 5 0 NA 80%


az.rejoice@gmail.com (Icy)

學校 : 臺北市立大安高級工業職業學校
編號 : 74619
來源 : [134.208.41.3]
最後登入時間 :
2024-03-18 01:01:11
b266. 矩陣翻轉 -- 2016 APCS 實作題第二題 | From: [111.246.63.46] | 發表日期 : 2019-11-17 17:44

有點不懂後面數字是怎麼跑出來的,輸入不是只有一組嗎? 為什麼最後輸出的答案跟正確答案完全不一樣?

因為是直接把輸入的數字加到列表裡操作,所以照理來說就算答案錯了應該也只會是順序出問題,結果輸出的答案跟正確答案裡面的數字完全不同,這不是很奇怪嗎>.<

求第五次測資謝謝

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]

 

 
#20031: Re:求解TT 您的答案為: 4 5 0 9 7 9 0 2 3 6 正確答案為: 7 3 3 1 3 1 0 6 5 0 NA 80%


az.rejoice@gmail.com (Icy)

學校 : 臺北市立大安高級工業職業學校
編號 : 74619
來源 : [134.208.41.3]
最後登入時間 :
2024-03-18 01:01:11
b266. 矩陣翻轉 -- 2016 APCS 實作題第二題 | From: [220.135.132.138] | 發表日期 : 2019-11-18 19:46

有點不懂後面數字是怎麼跑出來的,輸入不是只有一組嗎? 為什麼最後輸出的答案跟正確答案完全不一樣?

因為是直接把輸入的數字加到列表裡操作,所以照理來說就算答案錯了應該也只會是順序出問題,結果輸出的答案跟正確答案裡面的數字完全不同,這不是很奇怪嗎>.<

求第五次測資謝謝

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]

 


沒事,沒看清楚題目,過了

 
ZeroJudge Forum