fork download
  1. #include <stdio.h>
  2.  
  3. void getdigits(char buf[], int n)
  4. {
  5. while (n) {
  6. *buf++ = n % 10;
  7. n /= 10;
  8. }
  9. }
  10.  
  11. int is_vampire(const char n[4], const char i[2], const char j[2])
  12. {
  13. /* maybe a bit faster if unrolled manually */
  14. if (i[0] == n[0]
  15. && i[1] == n[1]
  16. && j[0] == n[2]
  17. && j[1] == n[3])
  18. return 1;
  19.  
  20. if (i[0] == n[0]
  21. && i[1] == n[1]
  22. && j[0] == n[3]
  23. && j[1] == n[2])
  24. return 1;
  25.  
  26. if (i[0] == n[0]
  27. && i[1] == n[2]
  28. && j[0] == n[1]
  29. && j[1] == n[3])
  30. return 1;
  31.  
  32. if (i[0] == n[0]
  33. && i[1] == n[2]
  34. && j[0] == n[3]
  35. && j[1] == n[1])
  36. return 1;
  37.  
  38. if (i[0] == n[0]
  39. && i[1] == n[3]
  40. && j[0] == n[1]
  41. && j[1] == n[2])
  42. return 1;
  43.  
  44. if (i[0] == n[0]
  45. && i[1] == n[3]
  46. && j[0] == n[2]
  47. && j[1] == n[1])
  48. return 1;
  49.  
  50.  
  51. if (i[0] == n[1]
  52. && i[1] == n[0]
  53. && j[0] == n[2]
  54. && j[1] == n[3])
  55. return 1;
  56.  
  57. if (i[0] == n[1]
  58. && i[1] == n[0]
  59. && j[0] == n[3]
  60. && j[1] == n[2])
  61. return 1;
  62.  
  63. if (i[0] == n[1]
  64. && i[1] == n[2]
  65. && j[0] == n[0]
  66. && j[1] == n[3])
  67. return 1;
  68.  
  69. if (i[0] == n[1]
  70. && i[1] == n[2]
  71. && j[0] == n[3]
  72. && j[1] == n[0])
  73. return 1;
  74.  
  75. if (i[0] == n[1]
  76. && i[1] == n[3]
  77. && j[0] == n[0]
  78. && j[1] == n[2])
  79. return 1;
  80.  
  81. if (i[0] == n[1]
  82. && i[1] == n[3]
  83. && j[0] == n[2]
  84. && j[1] == n[0])
  85. return 1;
  86.  
  87. if (i[0] == n[2]
  88. && i[1] == n[0]
  89. && j[0] == n[1]
  90. && j[1] == n[3])
  91. return 1;
  92.  
  93. if (i[0] == n[2]
  94. && i[1] == n[0]
  95. && j[0] == n[3]
  96. && j[1] == n[1])
  97. return 1;
  98.  
  99. if (i[0] == n[2]
  100. && i[1] == n[1]
  101. && j[0] == n[0]
  102. && j[1] == n[3])
  103. return 1;
  104.  
  105. if (i[0] == n[2]
  106. && i[1] == n[1]
  107. && j[0] == n[3]
  108. && j[1] == n[0])
  109. return 1;
  110.  
  111. if (i[0] == n[2]
  112. && i[1] == n[3]
  113. && j[0] == n[0]
  114. && j[1] == n[1])
  115. return 1;
  116.  
  117. if (i[0] == n[2]
  118. && i[1] == n[3]
  119. && j[0] == n[1]
  120. && j[1] == n[0])
  121. return 1;
  122.  
  123. if (i[0] == n[3]
  124. && i[1] == n[0]
  125. && j[0] == n[1]
  126. && j[1] == n[2])
  127. return 1;
  128.  
  129. if (i[0] == n[3]
  130. && i[1] == n[0]
  131. && j[0] == n[2]
  132. && j[1] == n[1])
  133. return 1;
  134.  
  135. if (i[0] == n[3]
  136. && i[1] == n[1]
  137. && j[0] == n[0]
  138. && j[1] == n[2])
  139. return 1;
  140.  
  141. if (i[0] == n[3]
  142. && i[1] == n[1]
  143. && j[0] == n[2]
  144. && j[1] == n[0])
  145. return 1;
  146.  
  147. if (i[0] == n[3]
  148. && i[1] == n[2]
  149. && j[0] == n[0]
  150. && j[1] == n[1])
  151. return 1;
  152.  
  153. if (i[0] == n[3]
  154. && i[1] == n[2]
  155. && j[0] == n[1]
  156. && j[1] == n[0])
  157. return 1;
  158.  
  159. return 0;
  160. }
  161.  
  162. int main()
  163. {
  164. for (int i = 10; i < 100; i++) {
  165. for (int j = 10; j < 100; j++) {
  166. int n = i * j;
  167. if (n < 1000)
  168. continue;
  169.  
  170. char ndigits[4];
  171. getdigits(ndigits, n);
  172.  
  173. char idigits[2];
  174. char jdigits[2];
  175. getdigits(idigits, i);
  176. getdigits(jdigits, j);
  177.  
  178. if (is_vampire(ndigits, idigits, jdigits))
  179. printf("%d * %d = %d\n", i, j, n);
  180. }
  181. }
  182.  
  183. return 0;
  184. }
  185.  
Success #stdin #stdout 0s 1792KB
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