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
|
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
using namespace std;
#define END 9
#define CORRECT_SUM 45
bool checkRows(int pTab[9][9]);
int main()
{
static int sudokuCorrect[9][9] =
{
{ 4, 6, 7, 3, 1, 5, 9, 2, 8 },
{ 1, 8, 2, 9, 4, 6, 7, 5, 3 },
{ 5, 3, 9, 2, 7, 8, 1, 4, 6 },
{ 6, 5, 3, 4, 8, 7, 2, 9, 1 },
{ 2, 7, 8, 1, 9, 3, 4, 6, 5 },
{ 9, 4, 1, 5, 6, 2, 8, 3, 7 },
{ 7, 9, 6, 8, 5, 4, 3, 1, 2 },
{ 8, 2, 4, 6, 3, 1, 5, 7, 9 },
{ 3, 1, 5, 7, 2, 9, 6, 8, 4 }
};
if (checkRows(sudokuCorrect) == true)
std::cout << "Sudoku correct!\n";
else
std::cout << "Sudoku incorrect :(\n";
int x;
cin >> x;
return 0;
}
bool checkRows(int pTab[9][9])
{
// ROW
for (int i = 0; i < END; i++)
{
int temp = 0;
// COLUMN
for (int j = 0; j < END; j++)
temp += pTab[i][j];
if (temp == CORRECT_SUM)
std::cout << "Row " << i + 1 << " correct.\n";
else
std::cout << "Row " << i + 1 << " incorrect.\ttemp = " << temp << std::endl;
if (temp != CORRECT_SUM)
return false;
}
return true;
}
|