05 我侬数
题目分析/解题思路
将原先的两个大整数组合再拆分为两个大整数,我们可以将A和B拼接后排序,也可以将二者的各位数字使用哈希表统计,之后我们再将每次读入的A'和B'也做同样的处理即可,最后比较处理结果即可。
注意:在处理之前需要先对大整数做去前导零的处理。
代码:
#include <bits/stdc++.h>
using namespace std;
string f(string a, string b) {
reverse(begin(a), end(a));
reverse(begin(b), end(b));
while (a.back() == '0') a.pop_back();
while (b.back() == '0') b.pop_back();
a = a + b;
sort(begin(a), end(a));
return a;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
string a, b;
cin >> a >> b;
a = f(a, b);
string x, y;
while (cin >> x >> y and x != "0" and y != "0") {
cout << (f(x, y) == a ? "Yes" : "No") << '\n';
}
return 0;
}