fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cstdint>
  5. #include <tuple>
  6.  
  7. typedef std::vector<std::tuple<std::uint64_t, std::uint64_t, std::uint64_t>> RType;
  8. typedef std::vector<std::uint64_t> DType;
  9.  
  10. DType SepDigit(std::uint64_t N){
  11. std::uint64_t V = 0;
  12. DType R;
  13. std::uint64_t Radix = 10;
  14.  
  15. while (N != 0){
  16. V = N % Radix;
  17. N /= Radix;
  18. R.push_back(V);
  19. }
  20.  
  21. return R;
  22. }
  23.  
  24. RType MakeHoge(){
  25. DType Ns{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  26. std::uint64_t A = 0, B = 0;
  27. std::uint64_t Ans = 0, C = 0;
  28. DType T;
  29. bool F = true;
  30. RType R;
  31. //std::uint64_t TT = 0;
  32. do{
  33. A = Ns[0] + (Ns[1] * 10) + (Ns[2] * 100) + (Ns[3] * 1000);
  34. B = Ns[4] + (Ns[5] * 10) + (Ns[6] * 100) + (Ns[7] * 1000);
  35. Ans = A*B;
  36. T = SepDigit(Ans);
  37. F = true;
  38. for (std::size_t i = 0; i < T.size(); i++){
  39. if (T[i] == Ns[8]) continue;
  40. if (T[i] == Ns[9]) continue;
  41. F = false;
  42. break;
  43.  
  44. }
  45. if (F == true){
  46. R.push_back(std::make_tuple(A, B, Ans));
  47. //std::cout << A <<"*"<< B <<"="<< Ans << std::endl;
  48. }
  49. //std::cout << TT++ << "\r";
  50. } while (std::next_permutation(Ns.begin(), Ns.end()));
  51. //std::cout << std::endl;
  52.  
  53. return R;
  54. }
  55.  
  56. bool Show(RType& R){
  57. for (auto& o : R){
  58. std::cout << std::get<0>(o) <<"*"<< std::get<1>(o) <<"="<< std::get<2>(o) << std::endl;
  59. }
  60. return true;
  61. }
  62.  
  63. int main(){
  64. auto R = MakeHoge();
  65. Show(R);
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 2.94s 3476KB
stdin
Standard input is empty
stdout
6712*5049=33888888
6712*5049=33888888
5132*867=4449444
5132*867=4449444
143*5796=828828
143*5796=828828
1924*357=686868
1924*357=686868
1274*539=686686
1274*539=686686
5796*143=828828
5796*143=828828
357*1924=686868
357*1924=686868
457*2869=1311133
457*2869=1311133
867*5132=4449444
867*5132=4449444
539*1274=686686
539*1274=686686
5049*6712=33888888
5049*6712=33888888
2869*457=1311133
2869*457=1311133