验证数独

题目大意:给定一个已完成的9*9的数独,判断结果是否正确

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int used[10];
int arr[10][10];

void solve() {
// 检验每个小数独
for (int x = 1; x <= 7; x += 3) {
for (int y = 1; y <= 7; y += 3) {
memset(used, 0, sizeof(used));
for (int i = x; i <= x + 2; i++) {
for (int j = y; j <= y + 2; j++) {
if (!used[arr[i][j]]) {
used[arr[i][j]] = 1;
} else {
cout << "Wrong" << endl;
return;
}
}
}
}
}
// 检验行
for (int i = 1; i <= 9; i++) {
memset(used, 0, sizeof(used));
for (int j = 1; j <= 9; j++) {
if (!used[arr[i][j]]) {
used[arr[i][j]] = 1;
} else {
cout << "Wrong" << endl;
return;
}
}
}
// 检验列
for (int i = 1; i <= 9; i++) {
memset(used, 0, sizeof(used));
for (int j = 1; j <= 9; j++) {
if (!used[arr[j][i]]) {
used[arr[j][i]] = 1;
} else {
cout << "Wrong" << endl;
return;
}
}
}
cout << "Right" << endl;
return;
}


int main(int argc, const char * argv[]) {
int n;
cin >> n;
while(n--) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
cin >> arr[i][j];
}
}
solve();
}
return 0;
}
script>