当前位置:网站首页>Judge whether it is Sudoku
Judge whether it is Sudoku
2022-07-02 08:41:00 【Tutu is a cat】
subject
Sudoku is a popular number filling game . The most typical Sudoku by 9*9 It's made up of squares , There will be some 1~ 9 The number of . Players need to fill in the numbers of the remaining grids , Make the row where each grid is located 、 Column 、 The small nine palaces contain 1~9 The number of , No weight, no leakage .
Now Xiao Ming has finished some Sudoku games with all the numbers filled in , Preparing to excavate . But before that , He wants you to check whether the problem surface is correct , That is, whether each grid of the completed question surface meets the line 、 Column 、 The little nine palaces contain 1~9.
Input
Enter a number in the first line T, Indicates the number of Sudoku puzzles Xiao Ming has completed .
After that, enter a total of 9 That's ok , Each row 9 The number is separated by a space , Indicates the number in the completed Sudoku .
Output
The output, T That's ok , A string on each line indicates whether the Sudoku is correct .
Output correctly "YES", If there is an error, output "NO".
Data range
about 100% The data of ,1≤T≤5,1≤ Every number ≤9.
sample input
2
7 6 2 5 9 3 1 4 8
9 4 1 2 7 8 5 3 6
8 3 5 4 6 1 7 9 2
1 9 8 6 2 7 3 5 4
4 7 6 3 5 9 2 8 1
2 5 3 8 1 4 6 7 9
3 8 7 1 4 6 9 2 5
5 1 4 9 3 2 8 6 7
6 2 9 7 8 5 4 1 3
8 1 4 7 3 2 6 5 9
9 2 3 6 5 8 1 4 7
5 7 6 4 9 1 2 8 3
3 4 5 2 6 7 8 9 1
1 8 9 3 4 5 3 2 6
2 6 7 1 8 9 5 3 4
7 5 1 9 2 4 7 6 8
4 3 8 5 7 6 9 1 2
6 9 2 8 1 3 4 7 5
sample output
YES
NO
Answer key
Go Language implementation
package main
import (
"fmt"
)
func main() {
// Input
var T int
fmt.Scan(&T)
if T < 1 || T > 5 {
fmt.Println("T Out of range ")
return
}
flag := true
var result [5] bool
for i := 0; i < T; i++ {
// Input array
var c [9][9] int
for i := 0; i < 9; i++ {
for j := 0; j < 9 ; j++ {
var num int
fmt.Scan(&num)
c[i][j] = num
}
}
for n := 0; n < 9 ; n++ {
// Better
if isRepetition(c[n]) {
flag = false
break
}
// Comparison column
var col [9] int
for k := 0; k < 9 ;k++ {
col[k] = c[k][n]
}
if isRepetition(col){
flag = false
break
}
}
if flag {
// squared paper for practicing calligraphy
var nine [9] int
for n := 0 ; n < 7; n++{
for k := 0 ; k < 7; k++{
nine[0] = c[n][k]
nine[1] = c[n+1][k]
nine[2] = c[n][k+1]
nine[3] = c[n+2][k]
nine[4] = c[n][k+2]
nine[5] = c[n+2][k+1]
nine[6] = c[n+1][k+2]
nine[7] = c[n+1][k+1]
nine[8] = c[n+2][k+2]
}
}
if isRepetition(nine) {
result[i] = false
}else {
result[i] = true
}
}else {
result[i] = false
}
}
for i := 0; i < T ; i++{
if result[i] {
fmt.Println("YES")
}else {
fmt.Println("NO")
}
}
}
// In the array 9 Whether the number is repeated
func isRepetition(numChar [9] int) bool {
for i := 0 ; i < len(numChar)-1; i++ {
for j := i+1; j < len(numChar); j++ {
if numChar[i] == numChar[j] {
return true
}
}
}
return false
}
边栏推荐
- [blackmail virus data recovery] suffix Hydra blackmail virus
- C language replaces spaces in strings with%20
- Jz-061-serialized binary tree
- Kubesphere virtualization KSV installation experience
- Live broadcast platform development, flexible menu, and freely adjust the horizontal size of the menu bar
- kubernetes部署loki日志系统
- 链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
- Programming ape learning English - imperative programming
- What are the platforms for selling green label domain names? What is the green label domain name like?
- Simple implementation scheme of transcoding and streaming (I)
猜你喜欢

Hcia - Application Layer

路由基础—动态路由

W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it

链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)

C language replaces spaces in strings with%20

HCIA—数据链路层

Application of kotlin - higher order function

Data asset management function

Web安全--核心防御机制

Sqli labs Level 2
随机推荐
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
sqli-labs第1关
Use the kaggle training model and download your own training model
Sqli labs Level 2
W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it
Pclpy projection filter -- projection of point cloud to cylinder
ARP and ARP Spoofing
Matlab mathematical modeling tool
HCIA—数据链路层
Valin cable: BI application promotes enterprise digital transformation
群辉 NAS 配置 iSCSI 存储
k8s入门:Helm 构建 MySQL
How to apply for a secondary domain name?
OpenFeign 简单使用
用数字 5,5,5,1 ,进行四则运算,每个数字当且仅当用一次,要求运算结果值为 24
kubeadm部署kubernetes v1.23.5集群
Programming ape learning English - imperative programming
类和对象(类和类的实例化,this,static关键字,封装)
Matlab-其它
Sentinel 简单使用