想了半天~还是没有一点思路!!!
键盘输入一个一位数的不成立的等式,当移动一根火柴后,如果能使等式成立,则输出成立的等式,否则输出“无解”。
#include <stdio.h> int main() { char d[10][10] = { {1, 0, 0, 0, 0, 0, 1, 0, 0, 1}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 1, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 1, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {1, 0, 0, 0, 0, 0, 1, 0, 0, 1}}; int a = 0, b = 0; printf("Please give me an equation of 2 1-digit natural numbers,\nwhich does not hold in this format: a = b\n> "); while (scanf("%d = %d", &a, &b) < 2 || a < 0 || a > 9 || b < 0 || b > 9) { while (getchar() != '\n'); printf("\nYour input is not valid, re-input\n> "); } printf("\n"); if (d[a][b]) { printf("%d = %d\n", b, b); } if (d[b][a]) { printf("%d = %d\n", a, a); } if (!d[a][b] && !d[b][a]) { printf("No solution.\n"); } return 0; }