#include
#include
#define N 22
int numCode[10][7] = { 1, 1, 1, 1, 1, 1, 0,
0, 1, 1, 0, 0, 0, 0,
1, 1, 0, 1, 1, 0, 1,
1, 1, 1, 1, 0, 0, 1,
0, 1, 1, 0, 0, 1, 1,
1, 0, 1, 1, 0, 1, 1,
1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, };
int stickCode[N];
int kinds;
int getNumber(int *p){
int i,j;
for (i = 0; i < 10; i++){
for (j = 0; j < 7; j++){
if (p[j] != numCode[i][j]){
break;
}
if (j == 6){
return i;
}
}
}
return -1;
}
void getStickCode(int num1, char oper, int num2, int num3){
int i;
int j;
for (i = 0; i < N; i++){
if (i < 7){
j = i;
stickCode[i] = numCode[num1][j];
}
else if (i < 14){
j = i - 7;
stickCode[i] = numCode[num2][j];
}
else if (i < 21){
j = i - 14;
stickCode[i] = numCode[num3][j];
}
else {
if (oper == '+'){
stickCode[i] = 1;
}
else {
stickCode[i] = 0;
}
}
}
}
void checkEquation(int *stickCodeAfterMove){
int num1;
int num2;
int num3;
int *p = stickCodeAfterMove;
num1 = getNumber(p);
num2 = getNumber(p + 7);
num3 = getNumber(p + 14);
if (num1 == -1 || num2 == -1 || num3 == -1){
return ;
}
if (p[21] == 1 && (num1 + num2 == num3)){
printf("%d + %d = %d\n", num1, num2, num3);
kinds++;
}
else if (p[21] == 0 && (num1 - num2 == num3)){
printf("%d - %d = %d\n", num1, num2, num3);
kinds++;
}
else {
return ;
}
}
int main(){
int stickCodeAfterMove[N];
getStickCode(1, '+', 0, 7);
memcpy(stickCodeAfterMove, stickCode, sizeof(stickCode));
int i,j;
for (i = 0; i < N; i++){
if (stickCode[i] == 1){
stickCodeAfterMove[i] = 0;
for (j = 0; j < N; j++){
if (stickCodeAfterMove[j] == 0){
stickCodeAfterMove[j] = 1;
checkEquation(stickCodeAfterMove);
stickCodeAfterMove[j] = 0;
}
}
stickCodeAfterMove[i] = 1;
}
}
if (kinds == 0){
printf("无法移动火柴使等式成立!\n");
}
return 0;
}