2022年c++的520钻石的答案

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小丑小克

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值