fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5. typedef std::vector<std::uint64_t> DType;
  6.  
  7. DType SepDigit(std::uint64_t N){
  8. std::uint64_t V;
  9. std::uint64_t Radix = 10;
  10. DType R;
  11. while (N != 0){
  12. V = N%Radix;
  13. N /= Radix;
  14. R.push_back(V);
  15. }
  16.  
  17. return R;
  18. }
  19.  
  20. std::uint64_t MakeHoge(std::uint64_t A, std::uint64_t B){
  21. auto AV = SepDigit(A);
  22. auto BV = SepDigit(B);
  23.  
  24. auto L = std::min(AV.size(), BV.size());
  25. std::uint64_t C=0;
  26.  
  27. AV.resize(L);
  28. BV.resize(L);
  29.  
  30. std::sort(BV.begin(), BV.end());
  31. BV.erase(std::unique(BV.begin(), BV.end()),BV.end());
  32.  
  33. for (auto& o : AV){
  34. C += std::count(BV.begin(), BV.end(),o);
  35. }
  36.  
  37. return C;
  38. }
  39. std::uint64_t MakeHoge2(std::uint64_t A, std::uint64_t B){
  40. auto AV = SepDigit(A);
  41. auto BV = SepDigit(B);
  42.  
  43. std::uint64_t j=0;
  44. auto L = std::min(AV.size(), BV.size());
  45.  
  46. AV.resize(L);
  47. BV.resize(L);
  48.  
  49. std::sort(AV.begin(), AV.end());
  50. std::sort(BV.begin(), BV.end());
  51.  
  52. for (std::size_t i = 0; i < std::min(AV.size(),BV.size()); i++)
  53. {
  54. if (AV[i] == BV[i]) continue;
  55. while (AV[i] < j){
  56. AV.erase(AV.begin() + i);
  57. if (AV.size() >= i)break;
  58. }
  59. while (BV[i] < j){
  60. BV.erase(BV.begin() + i);
  61. if (BV.size() >= i)break;
  62. }
  63. i--;
  64. j++;
  65. }
  66. return std::min(AV.size(),BV.size());
  67. }
  68. bool Show(std::uint64_t A, std::uint64_t B, std::uint64_t C){
  69. std::cout << A << ',' << B << " -> " << C << std::endl;
  70. return true;
  71. }
  72.  
  73. int main(){
  74. std::uint64_t A;
  75. std::uint64_t B;
  76. std::uint64_t C;
  77. /**/
  78. A = 110;
  79. B = 119;
  80. C = MakeHoge(A, B);
  81. Show(A, B, C);
  82.  
  83. A = 1234;
  84. B = 214;
  85. C = MakeHoge(A, B);
  86. Show(A, B, C);
  87.  
  88. A = 567;
  89. B = 23;
  90. C = MakeHoge(A, B);
  91. Show(A, B, C);
  92.  
  93. A = 233;//不可逆。仕様だ!
  94. B = 333;
  95. C = MakeHoge(A, B);
  96. Show(A, B, C);
  97. C = MakeHoge(B, A);
  98. Show(B, A, C);
  99. /**/
  100. //////////////////////////////////////
  101. std::cout << std::endl;
  102. //////////////////////////////////////
  103. A = 110;
  104. B = 119;
  105. C = MakeHoge2(A, B);
  106. Show(A, B, C);
  107.  
  108. A = 1234;
  109. B = 214;
  110. C = MakeHoge2(A, B);
  111. Show(A, B, C);
  112.  
  113. A = 567;
  114. B = 23;
  115. C = MakeHoge2(A, B);
  116. Show(A, B, C);
  117.  
  118. A = 233;//可逆。になった?!
  119. B = 333;
  120. C = MakeHoge2(A, B);
  121. Show(A, B, C);
  122. C = MakeHoge2(B, A);
  123. Show(B, A, C);
  124. return 0;
  125. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
110,119 -> 2
1234,214 -> 2
567,23 -> 0
233,333 -> 2
333,233 -> 3

110,119 -> 2
1234,214 -> 2
567,23 -> 0
233,333 -> 2
333,233 -> 2