-
Notifications
You must be signed in to change notification settings - Fork 4
/
sudoku2.cpp
72 lines (58 loc) · 1.09 KB
/
sudoku2.cpp
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
69
70
71
72
bool sudoku2(std::vector<std::vector<char>> grid) {
int arr[10] = { 0 };
int t;
unordered_set<int> left, right, middle;
for (int i = 0; i < grid.size(); i++)
{
if (i == 3 || i == 6)
{
left.clear();
right.clear();
middle.clear();
}
for (int j = 0; j < grid.size(); j++)
{
if (grid[i][j] != '.')
{
t = grid[i][j] - '0';
if (arr[t] > 0)
return false;
else
arr[t]++;
if (j / 3 == 0)
if(left.find(t) != left.end())
return false;
else
left.insert(t);
if (j / 3 == 1)
if(middle.find(t) != middle.end())
return false;
else
middle.insert(t);
if (j / 3 == 2)
if(right.find(t) != right.end())
return false;
else
right.insert(t);
}
}
for (int x = 0; x < 10; x++)
arr[x] = 0;
}
for (int j = 0; j < grid.size(); j++)
{
for (int i = 0; i < grid.size(); i++)
if (grid[i][j] != '.')
{
t = grid[i][j] - '0';
if (arr[t] > 0)
return false;
else
arr[t]++;
}
for (int x = 0; x < 10; x++)
arr[x] = 0;
cout << endl;
}
return true;
}