fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void getdigits(char buf[], int n)
  6. {
  7. while (n) {
  8. *buf++ = n % 10;
  9. n /= 10;
  10. }
  11. }
  12.  
  13. int compint(const void *a, const void *b)
  14. {
  15. return *(const char *)a - *(const char *)b;
  16. }
  17.  
  18. int is_vampire(char n[4], const char i[2], const char j[2])
  19. {
  20. char k[4] = { i[0], i[1], j[0], j[1] };
  21. qsort(k, 4, sizeof(k[0]), compint);
  22. qsort(n, 4, sizeof(n[0]), compint);
  23. return !memcmp(n, k, sizeof(k));
  24. }
  25.  
  26. int main()
  27. {
  28. for (int i = 10; i < 100; i++) {
  29. for (int j = 10; j < 100; j++) {
  30. int n = i * j;
  31. if (n < 1000)
  32. continue;
  33.  
  34. char ndigits[4];
  35. getdigits(ndigits, n);
  36.  
  37. char idigits[2];
  38. char jdigits[2];
  39. getdigits(idigits, i);
  40. getdigits(jdigits, j);
  41.  
  42. if (is_vampire(ndigits, idigits, jdigits))
  43. printf("%d * %d = %d\n", i, j, n);
  44. }
  45. }
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
15 * 93 = 1395
21 * 60 = 1260
21 * 87 = 1827
27 * 81 = 2187
30 * 51 = 1530
35 * 41 = 1435
41 * 35 = 1435
51 * 30 = 1530
60 * 21 = 1260
80 * 86 = 6880
81 * 27 = 2187
86 * 80 = 6880
87 * 21 = 1827
93 * 15 = 1395