#include <stdio.h>
bool invert_digit(int *n) { switch (*n) { case 0: case 1: case 2: case 5: case 8: break; case 6: *n = 9; break; case 9: *n = 6; break; default: return false; } return true; }
bool invert(int n, int *r) { int a[4], i; *r = 0; a[0] = n / 1000; a[1] = n % 1000 / 100; a[2] = n % 100 / 10; a[3] = n % 10; if (a[3] == 0) return false; for (i = 3; i >= 0; i--) { if (!invert_digit(a + i)) return false; *r = *r * 10 + a[i]; } return true; }
int main(void) { int a, b; int c, d; int e, f; for (a = 1000; a <= 9999; a++) { if (!invert(a, &c)) continue; for (b = 1000; b <= 9999; b++) { if (!invert(b, &d)) continue; e = c - a; f = b - d; if (e + f == 558) { if ((e >= 800 && e < 900 && f > -300 && f <= -200) || (f >= 800 && f < 900 && e > -300 && e <= -200)) { printf("%d => %d (%d), %d => %d (%d): %d\n", a, c, e, b, d, f, e + f); } } } } return 0; }
|