RockDrake

a016 normal

Aug 22nd, 2018
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. import sys
  2. def hLine():        #橫列
  3.     hCounter = 0
  4.     for i in range(0,9):
  5.         hList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  6.        
  7.         for j in range(0,9):
  8.             if np1[i][j] in hList:
  9.              hList.remove(np1[i][j])
  10.         if not hList:
  11.             hCounter += 1
  12.     if hCounter == 9:
  13.         return 'yes'
  14.  
  15.  
  16. def sLine():        #直行
  17.     sCounter = 0
  18.     for i in range(0,9):
  19.         sList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  20.        
  21.         for j in range(0,9):
  22.             if np1[j][i] in sList:
  23.                 sList.remove(np1[j][i])
  24.        
  25.         if not sList:
  26.             sCounter += 1
  27.     if sCounter == 9:
  28.         return 'yes'
  29.  
  30.  
  31. def sArea():        #3x3區域
  32.     temp = []
  33.     aCounter = 0
  34.     for i in range(0,8,3):
  35.         for j in range(0,8,3):
  36.             temp = [[None]*3 for i in range(0,3)]
  37.             for a in range(0,3):
  38.                 for b in range(0,3):
  39.                     temp[a][b] = np1[i+a][j+b]        # 切片
  40.             aList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  41.             for k in range(0,3):
  42.                 for m in range(0,3):
  43.                     if temp[k][m] in aList:
  44.                         aList.remove(temp[k][m])
  45.             if not aList:
  46.                 aCounter += 1
  47.     if aCounter == 9:
  48.         return 'yes'
  49.  
  50. data_counter = 0
  51. while True:
  52.     np1 = [[None]*9 for i in range(0,9)]
  53.     if data_counter != 0:
  54.         try:input()
  55.         except:break
  56.     for j in range(0,9):
  57.         a, b, c, d, e, f, g, h, i = input().split()
  58.         np1[j][0] = a
  59.         np1[j][1] = b
  60.         np1[j][2] = c
  61.         np1[j][3] = d
  62.         np1[j][4] = e
  63.         np1[j][5] = f
  64.         np1[j][6] = g
  65.         np1[j][7] = h
  66.         np1[j][8] = i
  67.     for g in range(0,9):
  68.         for h in range(0,9):
  69.             np1[g][h] = int(np1[g][h])
  70.     if hLine() == sLine() == sArea() =='yes':
  71.         print('yes')
  72.     else:
  73.         print('no')
  74.     data_counter += 1
Advertisement
Add Comment
Please, Sign In to add comment