AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 商店
  • 应用
  • 文章
    • 题解
    • 分享
    • 问答
  • 吐槽
  • 登录/注册

AcWing 3448. 基本算术    原题链接    简单

作者: 作者的头像   我呼吸了 ,  2022-08-06 17:48:16 ,  所有人可见 ,  阅读 7


3


#include <bits/stdc++.h>
using namespace std;

int add(vector<int> &A, vector<int> &B)
{
    int cnt = 0, t = 0;

    for(int i = 0; i < A.size() || i < B.size(); i ++)
    {
        if(i < A.size()) t += A[i];
        if(i < B.size()) t += B[i];

        t /= 10;
        if(t) cnt ++;
    }

    return cnt;
}

int main()
{
    string a, b;
    while(cin >> a >> b)
    {
        if(a == "0" && b == "0") break;

        vector<int> A, B;

        for(int i = a.size() - 1; i >= 0; i --) A.push_back(a[i] - '0');

        for(int i = b.size() - 1; i >= 0; i --) B.push_back(b[i] - '0');

        int res = add(A, B);

        if(res == 0) cout << "No carry operation." << endl;
        if(res == 1) cout << res << " carry operation." << endl;
        if(res > 1) cout << res << " carry operations." << endl;
    }

    return 0;
}

0 评论

你确定删除吗?

© 2018-2022 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息