fork download
  1. # your code goes here
  2. import sys
  3.  
  4. t = int(sys.stdin.readline())
  5. end = 0
  6. tav = []
  7. zbior = []
  8. while t > end:
  9. line = 1
  10. tab = []
  11.  
  12. while line <= 9:
  13. n = sys.stdin.readline().strip()
  14.  
  15. if n != '':
  16. put = n.split()
  17. tab.append(put)
  18. line += 1
  19.  
  20. tav.append(tab)
  21. dl = len(tav)
  22.  
  23. if t-1 == end :
  24.  
  25. for i in range(dl):
  26. zm = 1
  27. licz = 0
  28. for sp in tav[i][0]:
  29. if tav[i][0].count(sp)== 1:
  30. licz+=1
  31. if licz == 9:
  32. l = set(tav[i][0])
  33. zbior.append(l)
  34. elif tav[i][0].count(sp)>= 1 and zm == 9 :
  35. l = set(['a','b','c','d','e','f','g','h','i'])
  36. zbior.append(l)
  37. zm += 1
  38. dl_z = len(zbior)
  39. index = 0
  40. for ta in tav:
  41. answer = 0
  42. odp = 0
  43. for to in ta:
  44. if zbior[index].issubset(to):
  45. answer += 1
  46. else:
  47. answer = 0
  48. for j in range(9):
  49. taf = []
  50. for k in range(9):
  51. taf.append(ta[k][j])
  52. if zbior[index].issubset(taf):
  53. odp += 1
  54. else:
  55. odp = 0
  56.  
  57. if answer == 9 and odp == 9:
  58. print('TAK')
  59.  
  60. else:
  61. print('NIE')
  62. index += 1
  63. end += 1
Success #stdin #stdout 0.03s 27696KB
stdin
5
2 5 1 7 6 9 3 4 8
9 8 6 3 4 5 2 7 1
3 7 4 8 2 1 6 9 5
4 2 9 6 3 8 5 1 7
8 6 3 5 1 7 9 2 4
5 1 7 4 9 2 8 3 6
7 9 5 1 8 3 4 6 2
1 4 2 9 5 6 7 8 3
6 3 8 2 7 4 1 5 9

100 5 1 7 6 9 3 4 8
9 8 6 3 4 5 2 7 1
3 7 4 8 2 1 6 9 5
4 2 9 6 3 8 5 1 7
8 6 3 5 1 7 9 2 4
5 1 7 4 9 2 8 3 6
7 9 5 1 8 3 4 6 2
1 4 2 9 5 6 7 8 3
6 3 8 2 7 4 1 5 9

4 2 9 6 3 8 5 1 7
8 6 3 5 1 7 9 2 4
5 1 7 4 9 2 8 3 6
7 9 5 1 8 3 4 6 2
1 4 2 9 5 6 7 8 3
6 3 8 2 7 4 1 5 9
2 5 1 7 6 9 3 4 8
9 8 6 3 4 5 2 7 1
3 7 4 8 2 1 6 9 5

2 5 1 7 6 9 3 4 8
9 8 6 3 4 5 2 7 1
3 7 4 8 2 1 6 9 5
4 2 9 6 3 8 5 1 7
8 6 3 5 1 7 9 2 4
5 1 7 4 9 2 8 3 6
7 9 5 1 8 3 4 6 2
1 4 2 9 5 6 7 8 3
6 3 8 2 7 4 1 9 5

2 5 1 7 6 9 3 4 8
9 8 6 3 4 5 2 7 1
3 7 4 8 2 1 6 9 5
4 2 9 6 3 8 5 1 7
8 6 3 5 1 7 9 2 4
5 1 7 4 9 2 8 3 6
7 9 5 1 8 3 4 6 2
1 4 2 9 8 6 7 5 3
6 3 8 2 7 4 1 5 9
stdout
TAK
NIE
TAK
NIE
NIE