#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
typedef std::vector<std::uint64_t> DType;
DType SepDigit(std::uint64_t N){
std::uint64_t V;
std::uint64_t Radix = 10;
DType R;
while (N != 0){
V = N%Radix;
N /= Radix;
R.push_back(V);
}
return R;
}
std::uint64_t MakeHoge(std::uint64_t A, std::uint64_t B){
auto AV = SepDigit(A);
auto BV = SepDigit(B);
auto L = std::min(AV.size(), BV.size());
std::uint64_t C=0;
AV.resize(L);
BV.resize(L);
std::sort(BV.begin(), BV.end());
BV.erase(std::unique(BV.begin(), BV.end()),BV.end());
for (auto& o : AV){
C += std::count(BV.begin(), BV.end(),o);
}
return C;
}
bool Show(std::uint64_t A, std::uint64_t B, std::uint64_t C){
std::cout << A << ',' << B << " -> " << C << std::endl;
return true;
}
int main(){
std::uint64_t A;
std::uint64_t B;
std::uint64_t C;
A = 110;
B = 119;
C = MakeHoge(A, B);
Show(A, B, C);
A = 1234;
B = 214;
C = MakeHoge(A, B);
Show(A, B, C);
A = 567;
B = 23;
C = MakeHoge(A, B);
Show(A, B, C);
A = 233;//不可逆。仕様だ!
B = 333;
C = MakeHoge(A, B);
Show(A, B, C);
C = MakeHoge(B, A);
Show(B, A, C);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdHlwZWRlZiBzdGQ6OnZlY3RvcjxzdGQ6OnVpbnQ2NF90PiBEVHlwZTsKCkRUeXBlIFNlcERpZ2l0KHN0ZDo6dWludDY0X3QgTil7CglzdGQ6OnVpbnQ2NF90IFY7CglzdGQ6OnVpbnQ2NF90IFJhZGl4ID0gMTA7CglEVHlwZSBSOwoJd2hpbGUgKE4gIT0gMCl7CgkJViA9IE4lUmFkaXg7CgkJTiAvPSBSYWRpeDsKCQlSLnB1c2hfYmFjayhWKTsKCX0KCglyZXR1cm4gUjsKfQoKc3RkOjp1aW50N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