fork download
  1. #include <stdio.h>
  2. #define N 8
  3. int a[10] = {0};
  4. int b[10] = {0};
  5. void func(int n)
  6. {
  7. if (n == 0)
  8. {
  9. int aa, bb;
  10. aa = 0;
  11. for (int i = 0; i < N / 2; ++i)aa = aa * 10 + b[i];
  12. if (aa<1234)
  13. {
  14. return;
  15. }
  16. bb = 0;
  17. for (int i = N / 2; i < N; ++i)bb = bb * 10 + b[i];
  18. if (aa > bb)return;
  19. int ab = aa * bb;
  20. while (ab)
  21. {
  22. int w = ab % 10;
  23. for (int i = 0; i < N; ++i)
  24. if (b[i] == w)return;
  25. ab /= 10;
  26. }
  27. printf("answer : %d %d = %d\n", aa, bb, aa * bb);
  28. return;
  29. }
  30. for (int i = 0; i < 10; ++i)
  31. {
  32. if (a[i] == 0)
  33. {
  34. a[i] = 1;
  35. b[n - 1] = i;
  36. func(n - 1);
  37. a[i] = 0;
  38. }
  39. }
  40. }
  41. int main()
  42. {
  43. func(N);
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.18s 2248KB
stdin
Standard input is empty
stdout
answer : 5049 6712 = 33888888