Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import numpy as np
- def hLine(): #橫列
- hCounter = 0
- for i in range(0,9):
- hList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
- for j in range(0,9):
- if np1[i][j] in hList:
- hList.remove(np1[i][j])
- if not hList:
- hCounter += 1
- if hCounter == 9: # 9列都有1~9的數字,回傳確認訊號
- return 'yes'
- def sLine(): #直行
- sCounter = 0
- for i in range(0,9):
- sList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
- for j in range(0,9):
- if np1[j][i] in sList:
- sList.remove(np1[j][i])
- if not sList:
- sCounter += 1
- if sCounter == 9: # 9行都有1~9的數字,回傳確認訊號
- return 'yes'
- def sArea(): #3x3區域
- temp = []
- aCounter = 0
- for i in range(0,8,3):
- for j in range(0,8,3):
- temp = []
- temp = np1[i:i+3,j:j+3]
- aList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
- for k in range(0,3):
- for m in range(0,3):
- if temp[k][m] in aList:
- aList.remove(temp[k][m])
- print(aList)
- if not aList:
- aCounter += 1
- print(aCounter)
- if aCounter == 9: # 9區3X3都有1~9的數字,回傳確認訊號
- return 'yes'
- # 主程式
- for s in sys.stdin:
- np1 = np.zeros((9,9)) # 宣告
- for j in range(0,9):
- if j == 0:
- a0, b0, c0, d0, e0, f0, g0, h0, i0 = s.split() # 輸入第一筆至陣列
- np1[j][0] = a0
- np1[j][1] = b0
- np1[j][2] = c0
- np1[j][3] = d0
- np1[j][4] = e0
- np1[j][5] = f0
- np1[j][6] = g0
- np1[j][7] = h0
- np1[j][8] = i0
- elif j != 0:
- a, b, c, d, e, f, g, h, i = input().split() # 輸入其他筆至陣列
- np1[j][0] = a
- np1[j][1] = b
- np1[j][2] = c
- np1[j][3] = d
- np1[j][4] = e
- np1[j][5] = f
- np1[j][6] = g
- np1[j][7] = h
- np1[j][8] = i
- # 呼叫副程式並輸出
- if hLine() == sLine() == sArea() =='yes':
- print('yes')
- else:
- print('no')
- # Debug區域
- # print('hLine = ' + str(hLine()))
- # print('sLine = '+ str(sLine()))
- # print('sArea = ' + str(sArea()))
- # break
Advertisement
Add Comment
Please, Sign In to add comment