#25451: 求救!!! #0: 100% WA (line:5) 您共輸出 4 行。


s881123559978@gmail.com (E va)

學校 : 高雄市立高級商業職業學校
編號 : 122825
來源 : [1.200.190.81]
最後登入時間 :
2021-05-24 14:14:48
d481. 矩陣乘法 | From: [1.200.81.88] | 發表日期 : 2021-05-22 11:45

找了好久,但是都找不到錯誤QAQ

 

程式碼:

def data(num,c):
    lst = []
    for i in range(int(num)):
        ap = input().split(" ")
        if len(ap)==int(c):
            lst.append(ap)
        else:
            return "Error"
    return lst

def count(alist,blist):

    clist = []
    for i in range(len(alist)):#2
        newList = []
        ac = len(alist[i])
        bc = len(blist[0])
        for k in range(bc):
            new = 0
            for j in range(ac):
                new += int(alist[i][j]) * int(blist[j][k])
            newList.append(new)
        clist.append(newList)
    # print("C矩陣為:",clist)
    return clist

while True:
    try:
        inp = input().split(" ")
        if inp[1] == inp[2and (inp[1and inp[2])!=0:
            
            alist = data(inp[0],inp[1])   
            
            if alist != "Error":
                blist = data(inp[2],inp[3])
                if blist !="Error":
                    clist = count(alist,blist)
                    for i in range(len(clist)):
                        for k in clist[i]:
                            print(k,end=" ")
                        print()
                else:
                    print("Error")
                    break 
            else:
                print("Error")
                break   
            continue 
        else:
            print("Error")
            
        break
    except:
        print("Error")
        break
     

    
# alist = [[1,2,3],[4,5,6]]
# blist = [[3,4],[5,6],[7,8]]
 

 

 
 
#33169: Re: 求救!!! #0: 100% WA (line:5) 您共輸出 4 行。


w93816@gmail.com (411446510)

學校 : 淡江大學
編號 : 112141
來源 : [122.100.73.168]
最後登入時間 :
2024-06-14 17:31:13
d481. 矩陣乘法 | From: [36.224.251.174] | 發表日期 : 2022-12-07 22:32

找了好久,但是都找不到錯誤QAQ

 

程式碼:

def data(num,c):
    lst = []
    for i in range(int(num)):
        ap = input().split(" ")
        if len(ap)==int(c):
            lst.append(ap)
        else:
            return "Error"
    return lst

def count(alist,blist):

    clist = []
    for i in range(len(alist)):#2
        newList = []
        ac = len(alist[i])
        bc = len(blist[0])
        for k in range(bc):
            new = 0
            for j in range(ac):
                new += int(alist[i][j]) * int(blist[j][k])
            newList.append(new)
        clist.append(newList)
    # print("C矩陣為:",clist)
    return clist

while True:
    try:
        inp = input().split(" ")
        if inp[1] == inp[2and (inp[1and inp[2])!=0:
            
            alist = data(inp[0],inp[1])   
            
            if alist != "Error":
                blist = data(inp[2],inp[3])
                if blist !="Error":
                    clist = count(alist,blist)
                    for i in range(len(clist)):
                        for k in clist[i]:
                            print(k,end=" ")
                        print()
                else:
                    print("Error")
                    break 
            else:
                print("Error")
                break   
            continue 
        else:
            print("Error")
            
        break
    except:
        print("Error")
        break
     

    
# alist = [[1,2,3],[4,5,6]]
# blist = [[3,4],[5,6],[7,8]]
 

 

 

print error 後不要直接 break

 
ZeroJudge Forum