19 |
***************************************************************************/ |
***************************************************************************/ |
20 |
#include "solution.h" |
#include "solution.h" |
21 |
|
|
22 |
|
#include <iostream> |
23 |
|
|
24 |
Solution::Solution(int size) |
using namespace std; |
|
{ |
|
|
m_size = size; |
|
|
for (int i=0; i<m_size; i++) |
|
|
for (int j=0; j<m_size; j++) |
|
|
m_matrix[i][j] = false; |
|
|
} |
|
25 |
|
|
26 |
|
void Solution::print() |
|
Solution::~Solution() |
|
27 |
{ |
{ |
28 |
|
print(false, -1, -1); |
29 |
} |
} |
30 |
|
|
31 |
|
void Solution::print(bool debug, int row, int col) |
|
Solution::Solution(const Solution &input) |
|
|
{ |
|
|
m_size = input.m_size; |
|
|
for (int i=0; i<m_size; i++) |
|
|
for (int j=0; j<m_size; j++) |
|
|
m_matrix[i][j] = input.m_matrix[i][j]; |
|
|
} |
|
|
|
|
|
|
|
|
void Solution::set(bool input[MAX_SIZE][MAX_SIZE]) |
|
32 |
{ |
{ |
33 |
for (int i=0; i<m_size; i++) |
for (int i=0; i<m_size; i++) { |
34 |
for (int j=0; j<m_size; j++) |
for (int j=0; j<m_size; j++) |
35 |
m_matrix[i][j] = input[i][j]; |
cout << "+--"; |
36 |
} |
cout << "+" << endl; |
|
|
|
|
|
|
|
void Solution::rotate90() |
|
|
{ |
|
|
bool temp[MAX_SIZE][MAX_SIZE]; |
|
|
|
|
|
for (int i=0; i<m_size; i++) |
|
37 |
for (int j=0; j<m_size; j++) { |
for (int j=0; j<m_size; j++) { |
38 |
temp[j][(m_size-1)-i] = m_matrix[i][j]; |
cout << "|"; |
39 |
|
if (debug==true && row!=-1 && i==row && j==col) |
40 |
|
cout << "??"; |
41 |
|
else |
42 |
|
cout << ( getMatrix(i,j)==true ? "QQ" : " "); |
43 |
} |
} |
44 |
set(temp); |
cout << "|" << endl; |
45 |
} |
} |
46 |
|
for (int j=0; j<m_size; j++) |
47 |
void Solution::mirror() |
cout << "+--"; |
48 |
{ |
cout << "+" << endl; |
|
bool temp[MAX_SIZE][MAX_SIZE]; |
|
|
|
|
|
for (int i=0; i<m_size; i++) |
|
|
for (int j=0; j<m_size;j++) |
|
|
temp[i][(m_size-1)-j] = m_matrix[i][j]; |
|
|
set(temp); |
|
|
} |
|
|
|
|
|
|
|
|
bool Solution::operator==(const Solution& sol) |
|
|
{ |
|
|
for (int i=0; i<m_size; i++) |
|
|
for (int j=0; j<m_size; j++) |
|
|
if (m_matrix[i][j] != sol.m_matrix[i][j]) |
|
|
return false; |
|
|
return true; |
|
|
} |
|
|
|
|
|
bool Solution::operator!=(const Solution& sol) |
|
|
{ |
|
|
int matchcount = 0; |
|
|
for (int i=0; i<m_size; i++) |
|
|
for (int j=0; j<m_size; j++) |
|
|
if (m_matrix[i][j] == sol.m_matrix[i][j]) |
|
|
matchcount++; |
|
|
if (matchcount == (m_size*2) ) |
|
|
return false; |
|
|
else |
|
|
return true; |
|
|
} |
|
|
|
|
|
bool Solution::getMatrix(int x, int y) { |
|
|
return m_matrix[x][y]; |
|
|
} |
|
|
|
|
|
void Solution::setMatrix(int x, int y, bool val) { |
|
|
m_matrix[x][y] = val; |
|
|
} |
|
|
|
|
|
|
|
|
Solution* Solution::copy() |
|
|
{ |
|
|
return new Solution(*this); |
|
49 |
} |
} |