#include <vector>
#include <iostream>
using namespace std;
bool Checked[10];
void ResetChecked()
{
for (int i = 0; i < 10; ++i)
Checked[i] = false;
}
bool IsValidSudoku(char board[][10])
{
for (int i = 0; i < 9; ++i)
{
ResetChecked();
for (int j = 0; j < 9; ++j)
if (board[i][j] != '.')
{
int index = board[i][j] - '0';
if (Checked[index]) return false;
Checked[index] = true;
}
}
for (int j = 0; j < 9; ++j)
{
ResetChecked();
for (int i = 0; i < 9; ++i)
if (board[i][j] != '.')
{
int index = board[i][j] - '0';
if (Checked[index]) return false;
Checked[index] = true;
}
}
for (int i = 0; i < 9; ++i)
{
ResetChecked();
for (int j = 0; j < 9; ++j)
{
int r = i/3 *3 + j/3;
int c = i%3 *3 + j%3;
if (board[r][c] != '.')
{
int index = board[r][c] - '0';
if (Checked[index])
{
return false;
}
Checked[index] = true;
}
}
}
return true;
}
int main(int argc, char** argv)
{
char a[9][10] = {"53..7....","6..195...",".98....6.","8...6...3","4..8.3..1","7...2...6",".6....28.","...419..5","....8..79"};
bool isValid = IsValidSudoku(a);
cout << isValid;
return 0;
}