Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
153200 6倪葭轩 方阵填数 Python3 Compile Error 0 MS 0 KB 3952 2026-05-10 13:23:02

Tests(0/0):


Code:

import random as r res=0 while True: queue=[] board=[0]*25 score=0 def print_board(): for i in range(25): if (i+1)%5==0: print(board[i]) else: print(board[i],end=" ") for x in range(10): a1=r.randint(0,9) queue.append(a1) if res==1: ans = input('你准备好继续玩了吗?y/n') if ans == 'n': break else: ans = input('你准备好玩了吗?y/n') if ans == 'n': break print(f"初始化队列:{queue}") for e in range(r.randint(3,6)): board[r.randint(0,24)]=r.randint(1,9) while True: print_board() num=queue.pop(0) print(f"\n 当前取出的数为:{num}") try: row,col=input("输入行与列").split() row=int(row) col=int(col) pos=(row-1)*5+col-1 except: queue.insert(0, num) print('输入不合法!') continue if board[pos]>0: queue.insert(0,num) print(f"放置不合法!位置[{row}][{num}]已有数字") continue s=0 all_possible_pos=[] # 1 x, y = row, col nx, ny = x - 1, y - 1 if nx >= 1 and ny >= 1: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 2 x, y = row, col nx, ny = x - 1, y if nx >= 1: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 3 x, y = row, col nx, ny = x - 1, y + 1 if nx >= 1 and ny <= 5: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 4 x, y = row, col nx, ny = x, y - 1 if nx >= 1 and ny >= 1: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 5 x, y = row, col nx, ny = x, y + 1 if nx >= 1 and ny <= 5: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 6 x, y = row, col nx, ny = x + 1, y - 1 if nx <= 5 and ny >= 1: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 7 x, y = row, col nx, ny = x + 1, y if nx <= 5 and ny >= 1: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) # 8 x, y = row, col nx, ny = x + 1, y + 1 if nx <= 5 and ny <= 5: p = (nx - 1) * 5 + ny - 1 if board[p] > 0: s = s + board[p] all_possible_pos.append(p) if s==num or s%10==num: board[pos]=0 for p in all_possible_pos: board[p]=0 score=score+(1+len(all_possible_pos))*2 else: board[pos]=num print("你的得分为:",score) m=sum(queue) if m==0: print("----------你赢了!----------") res=1 break m2=0 for i in range(25): if board[i]!=0: m2=m2+1 if m2==25: print("----------你输了!----------") res=1 break queue.append(r.randint(1,9)) print(f"当前队列:{queue}")


Run Info:

  File "Main.py", line 29
    print(f"\u521d\u59cb\u5316\u961f\u5217\uff1a{queue}")
                         ^
SyntaxError: invalid syntax