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 <array>
#include <set>
using namespace std;
const string HORIZ = " + - - - + - - - + - - - +\n";
const string FOOTER = " 0 1 2 3 4 5 6 7 8\n\n";
struct Element
{
Element() :
Value(' '),
Possibilities({'1', '2', '3', '4', '5', '6', '7', '8', '9'})
{
}
set<char> Possibilities;
char Value;
};
void Show(const array<array<Element,9>, 9>& matrix)
{
for (int r=0; r<9; ++r)
{
if (r%3 == 0)
cout << HORIZ;
cout << r << " ";
for (int c=0; c<9; ++c)
{
if (c%3 == 0)
cout << "| ";
cout << matrix[r][c].Value << " ";
}
cout << "|" << endl;
}
cout << HORIZ;
cout << endl << FOOTER;
}
void Show(const set<char>& possibilities)
{
cout << "[";
for (auto& n : possibilities)
cout << n << " ";
cout << "]" << endl;
}
int main()
{
array<array<Element, 9>, 9> matrix;
matrix[0][0].Value = '1';
matrix[0][1].Value = '4';
matrix[0][2].Value = '6';
matrix[2][2].Value = 'X';
matrix[2][7].Value = '2';
matrix[8][2].Value = '7';
Show(matrix);
matrix[2][2].Possibilities = {'3', '5', '8', '9'};
cout << "possibilities for X at (2,2): ";
Show(matrix[2][2].Possibilities);
return 0;
}
|