fork(1) 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.  
  40. bool Show(std::uint64_t A, std::uint64_t B, std::uint64_t C){
  41. std::cout << A << ',' << B << " -> " << C << std::endl;
  42. return true;
  43. }
  44.  
  45. int main(){
  46. std::uint64_t A;
  47. std::uint64_t B;
  48. std::uint64_t C;
  49.  
  50. A = 110;
  51. B = 119;
  52. C = MakeHoge(A, B);
  53. Show(A, B, C);
  54.  
  55. A = 1234;
  56. B = 214;
  57. C = MakeHoge(A, B);
  58. Show(A, B, C);
  59.  
  60. A = 567;
  61. B = 23;
  62. C = MakeHoge(A, B);
  63. Show(A, B, C);
  64.  
  65. A = 233;//不可逆。仕様だ!
  66. B = 333;
  67. C = MakeHoge(A, B);
  68. Show(A, B, C);
  69. C = MakeHoge(B, A);
  70. Show(B, A, C);
  71. return 0;
  72. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
110,119 -> 2
1234,214 -> 2
567,23 -> 0
233,333 -> 2
333,233 -> 3