#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void getdigits(char buf[], int n)
{
while (n) {
*buf++ = n % 10;
n /= 10;
}
}
int compint(const void *a, const void *b)
{
return *(const char *)a - *(const char *)b;
}
int is_vampire(char n[4], const char i[2], const char j[2])
{
char k[4] = { i[0], i[1], j[0], j[1] };
qsort(k
, 4, sizeof(k
[0]), compint
); qsort(n
, 4, sizeof(n
[0]), compint
); return !memcmp(n
, k
, sizeof(k
)); }
int main()
{
for (int i = 10; i < 100; i++) {
for (int j = 10; j < 100; j++) {
int n = i * j;
if (n < 1000)
continue;
char ndigits[4];
getdigits(ndigits, n);
char idigits[2];
char jdigits[2];
getdigits(idigits, i);
getdigits(jdigits, j);
if (is_vampire(ndigits, idigits, jdigits))
printf("%d * %d = %d\n", i
, j
, n
); }
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKdm9pZCBnZXRkaWdpdHMoY2hhciBidWZbXSwgaW50IG4pCnsKICAgIHdoaWxlIChuKSB7CgkJKmJ1ZisrID0gbiAlIDEwOwoJCW4gLz0gMTA7Cgl9Cn0KCmludCBjb21waW50KGNvbnN0IHZvaWQgKmEsIGNvbnN0IHZvaWQgKmIpCnsKCXJldHVybiAqKGNvbnN0IGNoYXIgKilhIC0gKihjb25zdCBjaGFyICopYjsKfQoKaW50IGlzX3ZhbXBpcmUoY2hhciBuWzRdLCBjb25zdCBjaGFyIGlbMl0sIGNvbnN0IGNoYXIgalsyXSkKewoJY2hhciBrWzRdID0geyBpWzBdLCBpWzFdLCBqWzBdLCBqWzFdIH07Cglxc29ydChrLCA0LCBzaXplb2Yoa1swXSksIGNvbXBpbnQpOwoJcXNvcnQobiwgNCwgc2l6ZW9mKG5bMF0pLCBjb21waW50KTsKCXJldHVybiAhbWVtY21wKG4sIGssIHNpemVvZihrKSk7Cn0KCmludCBtYWluKCkKewoJZm9yIChpbnQgaSA9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