#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;
}
std::uint64_t MakeHoge2(std::uint64_t A, std::uint64_t B){
auto AV = SepDigit(A);
auto BV = SepDigit(B);
std::uint64_t j=0;
auto L = std::min(AV.size(), BV.size());
AV.resize(L);
BV.resize(L);
std::sort(AV.begin(), AV.end());
std::sort(BV.begin(), BV.end());
for (std::size_t i = 0; i < std::min(AV.size(),BV.size()); i++)
{
if (AV[i] == BV[i]) continue;
while (AV[i] < j){
AV.erase(AV.begin() + i);
if (AV.size() >= i)break;
}
while (BV[i] < j){
BV.erase(BV.begin() + i);
if (BV.size() >= i)break;
}
i--;
j++;
}
return std::min(AV.size(),BV.size());
}
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);
/**/
//////////////////////////////////////
std::cout << std::endl;
//////////////////////////////////////
A = 110;
B = 119;
C = MakeHoge2(A, B);
Show(A, B, C);
A = 1234;
B = 214;
C = MakeHoge2(A, B);
Show(A, B, C);
A = 567;
B = 23;
C = MakeHoge2(A, B);
Show(A, B, C);
A = 233;//可逆。になった?!
B = 333;
C = MakeHoge2(A, B);
Show(A, B, C);
C = MakeHoge2(B, A);
Show(B, A, C);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdHlwZWRlZiBzdGQ6OnZlY3RvcjxzdGQ6OnVpbnQ2NF90PiBEVHlwZTsKCkRUeXBlIFNlcERpZ2l0KHN0ZDo6dWludDY0X3QgTil7CglzdGQ6OnVpbnQ2NF90IFY7CglzdGQ6OnVpbnQ2NF90IFJhZGl4ID0gMTA7CglEVHlwZSBSOwoJd2hpbGUgKE4gIT0gMCl7CgkJViA9IE4lUmFkaXg7CgkJTiAvPSBSYWRpeDsKCQlSLnB1c2hfYmFjayhWKTsKCX0KCglyZXR1cm4gUjsKfQoKc3RkOjp1aW50NjRfdCBNYWtlSG9nZShzdGQ6OnVpbnQ2NF90IEEsIHN0ZDo6dWludDY0X3QgQil7CglhdXRvIEFWID0gU2VwRGlnaXQoQSk7CglhdXRvIEJWID0gU2VwRGlnaXQoQik7CgoJYXV0byBMID0gc3RkOjptaW4oQVYuc2l6ZSgpLCBCVi5zaXplKCkpOwoJc3RkOjp1aW50NjRfdCBDPTA7CgoJQVYucmVzaXplKEwpOwoJQlYucmVzaXplKEwpOwoKCXN0ZDo6c29ydChCVi5iZWdpbigpLCBCVi5lbmQoKSk7CglCVi5lcmFzZShzdGQ6OnVuaXF1ZShCVi5iZWdpbigpLCBCVi5lbmQoKSksQlYuZW5kKCkpOwoKCWZvciAoYXV0byYgbyA6IEFWKXsKCQlDICs9IHN0ZDo6Y291bnQoQlYuYmVnaW4oKSwgQlYuZW5kKCksbyk7Cgl9CgoJcmV0dXJuIEM7Cn0Kc3RkOjp1aW50NjRfdCBNYW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